TriFrost

TriFrost Docs

Learn and build with confidence, from a first project with workers to global scale on bare metal.

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 use console.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 or OtelHttpExporter
  • πŸ’‘ 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

Resources

Loved the read? Share it with others