Skip to content

Configuration

Log Level

typescript
setLogLevel(level: LogLevel): void
getLogLevel(): LogLevel

Default: "info". Override with LOG_LEVEL env var.

typescript
setLogLevel("debug") // debug, info, warn, error
setLogLevel("error") // error only
setLogLevel("silent") // nothing

Log Format

typescript
setLogFormat(format: LogFormat): void
getLogFormat(): LogFormat

Default: "console". Override with LOG_FORMAT env var. Also auto-enabled by NODE_ENV=production.

typescript
setLogFormat("json") // {"time":"...","level":"info","name":"myapp","msg":"..."}
setLogFormat("console") // 14:32:15 INFO myapp message

Span Control

typescript
enableSpans(): void
disableSpans(): void
spansAreEnabled(): boolean

Trace Filter

typescript
setTraceFilter(namespaces: string[] | null): void
getTraceFilter(): string[] | null

Only emit spans matching these namespace prefixes.

typescript
setTraceFilter(["myapp:db"]) // Only db spans
setTraceFilter(null) // All spans

Debug Filter

typescript
setDebugFilter(namespaces: string[] | null): void
getDebugFilter(): string[] | null

Filter log output by namespace. Supports negative patterns.

typescript
setDebugFilter(["myapp"]) // Only myapp and children
setDebugFilter(["myapp", "-myapp:sql"]) // Exclude sql
setDebugFilter(null) // All namespaces

Auto-lowers log level to debug when set.

Output Mode

typescript
setOutputMode(mode: OutputMode): void
getOutputMode(): OutputMode
setSuppressConsole(value: boolean): void
ModeConsoleWriters
"console"YesYes
"stderr"stderrYes
"writers-only"NoYes

Environment Variables

VariableValuesDefault
LOG_LEVELtrace, debug, info, warn, error, silentinfo
LOG_FORMATconsole, jsonconsole
DEBUG*, namespace prefixes, -prefix(none)
TRACE1, true, namespace prefixes(none)
TRACE_FORMATjson(none)
NODE_ENVproduction(none)

Released under the MIT License.