Logger
Deliver consistent log output across local runs and CI without wiring custom formatting by hand.
Summary
The Logger battery locks down terminal output with environment-aware level gating, scope-able helpers, and ANSI-safe formatting so debug chatter stays in dev and production logs stay spotless.
Why Use This Battery?
- Delivers out-of-the-box logging, so you skip the busywork of customizing
consolewrappers. - Automatically adjusts verbosity based on
NODE_ENVand allows you to override throughLOG_LEVEL. - Produces color-coded output by default, with optional timestamps for easier reading.
Capabilities
- Messages with line breaks are indented on subsequent lines for readability.
- Automatically adapts to environment signals (frontend vs. backend) and the
LOG_LEVELsetting. - Add timestamps to prefixes by setting the
LOG_TIMEenvironment flag. - Teams can call
Logger.customizeto reuse shared options like padding or component names.
Usage
Development Logging
Logger.dev is meant for local debugging (enhanced version of console.log). Enable the no-logger-dev ESLint rule to protect you from leaking logs.
Output Examples
Customize
Tune the runtime behavior with the environment variables and options below.
Environment Variables
Before you run a script, set LOG_LEVEL for the right verbosity and toggle LOG_TIME to 'true' when you want timestamped output.
| Setting | Type | Default | Description |
|---|---|---|---|
LOG_LEVEL | string | 'debug' when NODE_ENV=development; 'warn' for browser production; otherwise 'info' | Minimum level emitted; accepts debug, dev, info, warn, error. |
LOG_TIME | string | — | Set to the string 'true' to prefix each message with an ISO timestamp. |
NODE_ENV | string | — | Controls the default LOG_LEVEL; set to 'development' for chatty logs. |
Options
Call Logger.customize({ ... }) to spin up scoped loggers, giving each phase a name and using padding to separate sections in the terminal.
Scope Tags
Scope tags (name, type, and purpose options) render only when LOG_LEVEL is 'debug' or NODE_ENV is 'development'.
| Option | Type | Default | Description |
|---|---|---|---|
name | string | — | The first segment shows who is emitting (e.g., function name). |
type | 'function' | 'method' | 'test' | — | The second segment highlighting what is emitting. |
purpose | string | — | The third segment that calls out the intent of this log. |
padTop | number | 0 | Inserts that many blank lines before the payload (values below 0 are ignored). |
padBottom | number | 0 | Inserts that many blank lines after the payload (values below 0 are ignored). |
Troubleshooting
- Nothing prints to the terminal — Check
LOG_LEVEL; if it is set higher than your message severity, downgrade it or unset it entirely. - Colors missing in CI logs — Some environments disable ANSI. Export
FORCE_COLOR=1or rely on timestamps/names for identification. - Extra blank lines surround messages — Review
padTop/padBottomon customized loggers and reset them to0when not needed. - Timestamps not appearing —
LOG_TIMEexpects the exact string'true', not any other truthy value. - Debug logs still hidden locally — Confirm
NODE_ENVis'development'or explicitly setLOG_LEVEL=debug.