Logface is highly configurable. You can control log output style, emoji, color, and more.
- Place a
logface.config.js(CommonJS/ESM) orlogface.config.mjs(ESM) in your project root. - See
logface.example.config.jsfor a template.
// logface.config.js
module.exports = {
emojiRandom: true,
emojis: {
debug: ["π", "π", "π¦ "],
info: ["βΉοΈ", "π‘", "π§"],
log: ["π", "π", "ποΈ"],
warn: ["β οΈ", "π§", "π"],
error: ["π₯", "π₯", "π£"],
},
colorEnabled: true,
colorLibrary: "kleur",
};// logface.config.js
module.exports = {
emojiRandom: false,
emojis: { debug: "", info: "", log: "", warn: "", error: "" },
colorEnabled: false,
};.jscan be CommonJS or ESM (depends onpackage.jsontypefield)..mjsis always ESM.
- Emoji are added as a prefix by logface (not stripped from your message).
- Disabling emoji/color only affects the prefix, not your message content.
- Randomization (
emojiRandom: true) picks a random emoji from the array for each log message.
- Ignore
logface.config.jsin git (add to.gitignore). - Use the example config as a starting point.
- For stable test output, disable emoji and color in your test config or via environment variables.
- Log Levels
- Runtime Log Level
- Debug Gating
- Filtering with LOG/LOG_VERBOSE
- Wildcard Filtering
- Silent Mode
- Tagging and Scoping
- Testing Log Output
- Best Practices
- Example: Silent Logging in Production/Edge/Serverless
- Negation Filtering
Logface supports the following log levels:
debuginfowarnerrorlog(always emitted unless silent)
You can control which log levels are emitted at runtime:
log.level = "warn"; // Only warn, error, and log will be emitted
log.setLogLevel("error"); // Only error and log will be emitted
log.level = "silent"; // Suppress all output
log.level = "debug"; // Restore to default (all logs, if allowed by filters)- The runtime log level is respected unless
LOGorLOG_VERBOSEis set in the environment. - If
LOG/LOG_VERBOSEis set, those take precedence for filtering. - Setting
log.level = 'silent'orlog.setLogLevel('silent')suppresses all output.
Debug output is always gated:
- Debug logs are only emitted if
LOG/LOG_VERBOSEmatches the tag/level, or iflog.levelis'debug'andDEBUG=1is set in the environment. - This ensures debug output is never shown unless explicitly enabled.
You can filter logs by tag or level using environment variables:
LOG=auth node app.js
LOG=metrics,debug,auth* node app.js
LOG_VERBOSE=api* node app.js- Wildcards are supported (e.g.
auth:*,metrics*). - If neither
LOGnorLOG_VERBOSEis set, the runtime log level is used.
- Use wildcards to match multiple tags or levels.
- Examples:
LOG=auth*matches any tag starting withauthLOG=debug,metrics*matches debug logs and any tag starting withmetrics
- Set
log.level = 'silent'orlog.setLogLevel('silent')to suppress all log output. - This is useful for tests or production environments where no logs should be emitted.
- Use
log.options({ tag })to scope logs:
log.options({ tag: "auth" }).info("User login");
log.options({ tag: "metrics", timestamp: true }).debug("Memory usage");- You can also set global options with
log.setup({ ... }).
- To test debug output, set
process.env.DEBUG = '1'in your test setup. - To test filtering, set
process.env.LOGorprocess.env.LOG_VERBOSEas needed. - Use the runtime log level to control output in tests:
log.level = "warn";
log.level = "silent";- Always use
log.options({ tag })for scoping logs. - Avoid using
log.withTag(deprecated). - Never hardcode secrets or credentials in logs.
- Use runtime log level and environment variables to control output in different environments.
- Document your log tags and levels for maintainability.
- Use
log.level = 'silent'in tests unless you are explicitly testing log output.
In production or serverless environments (like Cloudflare Workers), you may want to suppress all log output by default to avoid unnecessary costs or noise.
// At the top of your worker or server entrypoint
import logface from 'logface';
if (process.env.NODE_ENV === 'production' || process.env.CF_PAGES) {
logface.setLogLevel('silent');
}Or, in your config file:
// logface.config.js
module.exports = {
// ...other config...
level: process.env.NODE_ENV === 'production' ? 'silent' : 'debug'
};Tip: Cloudflare Workers and some edge platforms may require a paid plan to view logs. Suppressing logs by default is a best practice for production deployments.
- Negation is supported in LOG/LOG_VERBOSE patterns:
- Prefix a pattern with
!to suppress logs matching that pattern, unless also matched by a positive pattern. - Example:
LOG="!foo;auth,debug"suppresses logs with tagfoounless they also matchauthordebug. - Negation and positive patterns can be combined with commas or semicolons.
- Prefix a pattern with
For more details, see the main README.md.