g14o
Packages@g14o/logger

API Reference

Types and options for createLogger and built-in transports.

createLogger

import { createLogger } from "@g14o/logger";

const logger = createLogger(options);

Returns a Logger.

LoggerOptions

OptionTypeDescription
formatOptions?object

Output formatting (timestamps, meta, name segment, alignment, colors, stacks).

level?LogLevel | undefined

Minimum severity to emit.

Default: `"info"`.
name?string

Logger name included in every log line when provided.

redact?array

Key names to redact recursively in meta objects (case-insensitive).

transports?array

Output transports. Default single console transport.

FormatOptions

OptionTypeDescription
align?number | false | undefined

Min terminal width for right-aligned timestamps; false = always compact.

Default: `80`.
colors?boolean | "auto" | undefined

Pretty color override (true / false / "auto").

Default: `"auto"`.
json?object

JSON serialization (field order and indentation).

levels?Partial<Record<ActiveLogLevel, object>>

Per-level glyph/label/kind overrides for console prefixes.

meta?boolean | undefined

Inline meta JSON on console lines.

Default: `true`.
name?boolean | undefined

[name] segment on console lines.

Default: `true`.
pretty?boolean | undefined

Pretty console mode (glyphs/badges). Applies to console transports.

Default: `false`.
stack?boolean | undefined

Stack frames in pretty error/fatal output.

Default: `true`.
time?TimestampOption | undefined

Timestamp display. Formats: "time" | "time12" | "iso" | "utcString". Set to false or { enabled: false } to omit timestamps.

Default: enabled with `"time"` (`HH:MM:SS`) and timezone `"utc"`.

LevelFormatOptions

OptionTypeDescription
fallbackSymbol?string

ASCII fallback when Unicode glyphs are unsupported.

kind?LevelPrefixKind | undefined

Prefix kind: colored glyph or background badge.

label?string

Uppercase label used by plain output and badges.

symbol?string

Unicode glyph for symbol prefixes.

JsonFormatOptions

OptionTypeDescription
fieldOrder?array

Ordered field groups. meta expands to alphabetically sorted metadata keys. Missing groups append in the default order. Duplicates are ignored after first use.

Default: `["timestamp", "level", "name", "message", "meta"]`.
pretty?number | boolean | undefined

Pretty-print JSON. true uses 2 spaces; a number uses that indentation (clamped to 0–10). Default is compact one-line output.

Default: `false`.

Logger

PropTypeDescription
childfunction

Returns a child logger that merges bindings into every subsequent log.

debugfunction

Logs diagnostic details at the debug level. Hidden by the default threshold.

errorfunction

Logs a recoverable failure at the error level with structured error details.

fatalfunction

Logs an unrecoverable failure at the highest severity level.

infofunction

Logs general operational information at the default severity level.

startfunction

Logs the beginning or progress of a process at the info severity tier.

successfunction

Logs successful completion of a process at the info severity tier.

timefunction

Starts a timer for label. Returns a stop function that logs at success level with durationMs in meta.

tracefunction

Logs fine-grained diagnostic details at the lowest severity level.

warnfunction

Logs a potentially harmful or unexpected condition at the warn level.

withRequestIdfunction

Returns a child logger with requestId bound. Generates one when id is omitted.

Primary call shape is message, meta? for most levels. error and fatal accept error, message?. Broader (...args: unknown[]) overloads keep the type assignable to cache-style logger contracts; unsupported extra arguments are preserved under details, not printf-interpolated.

ConsoleTransport

OptionTypeDescription
formatOptions?object

Per-transport formatting overrides (deep-merged over logger formatOptions).

type"console"

Selects the human-readable console transport.

JsonTransport

OptionTypeDescription
formatOptions?object

Per-transport formatting overrides (deep-merged over logger formatOptions).

type"json"

Selects the structured JSON transport, emitting one object per line.

Timestamp and format types

Type / constantDescription
TimestampFormat"time" | "time12" | "iso" | "utcString"
TimestampTimezone"utc" | "local"
TimestampOptionboolean or { enabled: false } / { enabled: true; format?; timezone? }
JsonFieldGroup"timestamp" | "level" | "name" | "message" | "meta"
LevelPrefixKind"symbol" | "badge"

On this page