Logger: Console
The ConsoleExporter
in TriFrost is a structured, customizable logger that writes to the system console (console.log
, console.error
, etc).
It supports:
- Collapsed log grouping
- Log enrichment with tracing & context
- Field redaction (
omit
) - Custom formatting
Itβs the default exporter in development for all runtimes.
π₯ Import and Use
import {App, ConsoleExporter} from '@trifrost/core';
new App({
...
tracing: {
exporters: ({env}) => [
new ConsoleExporter({
grouped: true,
include: ['trace_id', 'ctx'],
omit: [...], // see below
format: log => `[${log.level.toUppercase()}] ${log.message}`,
}),
],
}
...
})
You provide this when configuring your App setup, there's sensible defaults at play so in most cases new ConsoleExporter()
will be enough.
βοΈ Available Options
grouped
: boolean
Whether logs with metadata should useconsole.groupCollapsed(...)
.
default:false
include
:'ctx' | 'trace_id' | 'span_id' | 'time' | 'level' | 'global'
Additional metadata to include in the log object.
default:[]
omit
: TriFrostLogScramblerValue[]
Keys to redact from data/ctx/global payloads. Learn more here
default:OMIT_PRESETS.default
format
: (log:TriFrostLogPayload) => string
Custom formatter for the top-level message.
default:[time] [level] message
Examples
Basic Configuration
new ConsoleExporter();
Prints:
[2025-06-06T10:30:00.000Z] [info] User logged in
Grouped with Trace ID
new ConsoleExporter({
grouped: true,
include: ['trace_id']
});
Output:
βΆ [2025-06-06T10:30:00Z] [info] User logged in\n trace_id: 3c51d...\n data: {userId: "abc123"}
Add Context & Global App Info
new ConsoleExporter({
include: ['trace_id', 'ctx', 'global']
});
Output includes:
{\n "ctx": {"method": "GET", "path": "/login"},\n "global": {"service.name": "my-app", "service.version": "1.2.3"}\n}
Custom Format Line
new ConsoleExporter({
format: log => `(${log.level.toUpperCase()}) ${log.message}`
});
Output:
(INFO) Session started
Redact Sensitive Fields
import {OMIT_PRESETS, ConsoleExporter} from '@trifrost/core';
new ConsoleExporter({
omit: [...OMIT_PRESETS.default, {global: 'ssn'}]
});
π See Scrambling Hygiene for full explanation
Best Practices
- β Use in dev or CI/CD jobs for lightweight structured output
- β
Combine with
include: ['ctx', 'trace_id']
to enrich log metadata - β Customize formatting to match your console style
- π‘ You can use this exporter in tandem with
JsonExporter
orOtelHttpExporter
- π‘ Want to go fancy? Make use of TriFrost's isDevMode function to refine between dev and prod
- β Donβt use in high-throughput prod β prefer OTEL-compatible exporters with a dedicated backend