Reference

Configuration

LoggerOptions and the fluent LoggerConfiguration.

Two spellings of the same thing. The options object is the JavaScript one; the fluent builder is Serilog's. createLogger() makes an independent logger; configure() reconfigures the global log in place, and every logger derived from it follows.

LoggerOptions#

configure({
  minimumLevel: 'info',
  overrides: { next: 'warn', 'app.db': 'verbose' },
  sinks: [consoleSink()],
  auditSinks: [],
  enrichers: [withProperty('Application', 'shop')],
  filters: [byExcluding(Matching.fromSource('health'))],
  destructuring: { maxDepth: 10, redact: ['password'] },
  properties: { Version: '1.4.0' },
  logContext: true,
  onSinkError: (error, sink, event) => { … },
});
OptionTypeDefault
minimumLevelLogLevel | string | LevelSwitch'info', or LOGIT_LEVELevents below it are dropped before capture
overridesRecord<string, LogLevel | string | LevelSwitch>{} + LOGIT_OVERRIDESper-SourceContext prefix, longest match wins
sinksSink[][consoleSink()] when neither sinks nor auditSinks is givenwhere events go; a Logger is a sink
auditSinksSink[][]sinks whose failure throws from the logging call
enrichersEnricher[][]run in order, after the context enricher
filtersFilter[][]all must return true
destructuringPartial<DestructuringOptions>see belowthe capture rules
propertiesRecord<string, unknown>—fixed properties; shorthand for withProperties()
logContextbooleantrueinclude fromLogContext()
onSinkError(error, sink, event) => voidselfLogwhere a non-audit sink's failure goes

DestructuringOptions#

OptionDefault
maxDepth10deeper values become '[Object]' / '[Array]'
maxStringLengthInfinitylonger strings are cut with …
maxCollectionCountInfinityarrays, Sets and Maps are cut
redact[]keys / dotted paths whose values are replaced
redactedValue'[Redacted]'
policies[]DestructuringPolicy[], first answer wins
typeTagtruewrite $type for destructured class instances

See Structured data and Redaction.

LoggerConfiguration#

import { LoggerConfiguration, configure, Matching } from '@unhingged/logit';

const logger = new LoggerConfiguration()
  .minimumLevel.debug()
  .minimumLevel.override('next', 'warn')
  .enrich.withProperty('Application', 'shop')
  .filter.byExcluding(Matching.fromSource('health'))
  .destructure.redact('password')
  .writeTo.console()
  .writeTo.seq({ serverUrl: 'http://localhost:5341' }, )
  .createLogger();

configure(new LoggerConfiguration().minimumLevel.info().writeTo.console()); // the global, from a builder

Every method returns the configuration, so calls chain.

GroupMethods
minimumLevelverbose() debug() info() / information() warn() / warning() error() fatal() · is(level) · controlledBy(levelSwitch) · override(source, level)
writeTosink(...sinks) · console(options?) · stream(stream, options?) · http(options) · seq(options) · logger(configure, restrictedToMinimumLevel?) — a sub-logger
auditTosink(...sinks)
enrichwith(...enrichers) · fromLogContext() · withProperty(name, value, destructure?) · withProperties(object, destructure?)
filterwith(...filters) · byExcluding(pred) · byIncludingOnly(pred)
destructuretoMaximumDepth(n) · toMaximumStringLength(n) · toMaximumCollectionCount(n) · with(...policies) · byTransforming(Type, fn) · redact(...keys)
readFromenv() — LOGIT_LEVEL / LOGIT_OVERRIDES are read by default; this makes it explicit
—withoutLogContext() · toOptions() → LoggerOptions · createLogger() → Logger

The file sink and the OpenTelemetry sinks live in their own entries and are added with .writeTo.sink(fileSink({ … })).

Defaults, in one place#

minimum levelinfo
sinksone console sink: pretty on a terminal or in a browser, JSON lines elsewhere
contextfromLogContext() on
destructuringdepth 10, no string / collection limits, no redaction, $type on
selfLogoff