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) => { … },
});| Option | Type | Default | |
|---|---|---|---|
minimumLevel | LogLevel | string | LevelSwitch | 'info', or LOGIT_LEVEL | events below it are dropped before capture |
overrides | Record<string, LogLevel | string | LevelSwitch> | {} + LOGIT_OVERRIDES | per-SourceContext prefix, longest match wins |
sinks | Sink[] | [consoleSink()] when neither sinks nor auditSinks is given | where events go; a Logger is a sink |
auditSinks | Sink[] | [] | sinks whose failure throws from the logging call |
enrichers | Enricher[] | [] | run in order, after the context enricher |
filters | Filter[] | [] | all must return true |
destructuring | Partial<DestructuringOptions> | see below | the capture rules |
properties | Record<string, unknown> | — | fixed properties; shorthand for withProperties() |
logContext | boolean | true | include fromLogContext() |
onSinkError | (error, sink, event) => void | selfLog | where a non-audit sink's failure goes |
DestructuringOptions#
| Option | Default | |
|---|---|---|
maxDepth | 10 | deeper values become '[Object]' / '[Array]' |
maxStringLength | Infinity | longer strings are cut with … |
maxCollectionCount | Infinity | arrays, Sets and Maps are cut |
redact | [] | keys / dotted paths whose values are replaced |
redactedValue | '[Redacted]' | |
policies | [] | DestructuringPolicy[], first answer wins |
typeTag | true | write $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 builderEvery method returns the configuration, so calls chain.
| Group | Methods |
|---|---|
minimumLevel | verbose() debug() info() / information() warn() / warning() error() fatal() · is(level) · controlledBy(levelSwitch) · override(source, level) |
writeTo | sink(...sinks) · console(options?) · stream(stream, options?) · http(options) · seq(options) · logger(configure, restrictedToMinimumLevel?) — a sub-logger |
auditTo | sink(...sinks) |
enrich | with(...enrichers) · fromLogContext() · withProperty(name, value, destructure?) · withProperties(object, destructure?) |
filter | with(...filters) · byExcluding(pred) · byIncludingOnly(pred) |
destructure | toMaximumDepth(n) · toMaximumStringLength(n) · toMaximumCollectionCount(n) · with(...policies) · byTransforming(Type, fn) · redact(...keys) |
readFrom | env() — 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 level | info |
| sinks | one console sink: pretty on a terminal or in a browser, JSON lines elsewhere |
| context | fromLogContext() on |
| destructuring | depth 10, no string / collection limits, no redaction, $type on |
| selfLog | off |