Skip to content

Logger

class Logger extends FlareService

Structured logger that emits records to one or more registered transports.

Filters records below the configured minimum level globally and per-transport, attaches request context from loggerALS when context capture is enabled, and drives transport startup and shutdown in registration order.

new Logger(transports, container)

new Logger(transports: LoggerTransport[], container: Container): Logger

transports LoggerTransport[]

container Container

config: readonly [ConfigToken<LogConfig>]

Declares the config tokens this class requires.

Parallel to static deps. When declared, this.config(token) validates that the token is in this array before resolving, identical to how this.inject(token) validates static deps.

deps: readonly []

Declares the service tokens this class is allowed to inject().

Tokens not listed here cause inject() to throw at the call site, naming both the class and the offending token.

config<T>(token: ConfigToken<T>): T

Resolves a typed config section by token.

Mirrors inject() + static deps: the class must declare a static config array, and the requested token must appear in it. Both checks throw a developer-facing error when violated.

token ConfigToken<T>

returns T

Example:

class DbService extends FlareService {
static config = [DbConfig];
async onStart() {
const { url } = this.config(DbConfig);
}
}

Throws:

When the class has no static config declaration.

Throws:

When the token is not present in static config.

debug(message: string, meta?: LogMeta): void

Emits a record at debug level.

message string

meta? LogMeta

dispose(): void | Promise<void>

Called at the end of every request for scoped services, whether the handler succeeded or threw.

This is a correctness boundary: the framework waits for any returned promise before completing the request pipeline. Use it for per-request cleanup that must finish, such as rolling back transactions, releasing locks, or closing cursors.

If a service wants fire-and-forget background work, schedule that work inside dispose() and return void. Implies scoped lifetime: declaring this on a singleton class throws at build() time.

returns void | Promise<void>

2 overloads

error(message: string, meta?: LogMeta): void

Emits a record at error level.

Pass an error value as the first argument to attach a structured error field assembled via toErrorField.

message string

meta? LogMeta

error(error: unknown, message: string, meta?: LogMeta): void

Emits a record at error level.

Pass an error value as the first argument to attach a structured error field assembled via toErrorField.

error unknown

message string

meta? LogMeta

2 overloads

fatal(message: string, meta?: LogMeta): void

Emits a record at fatal level.

Pass an error value as the first argument to attach a structured error field assembled via toErrorField.

message string

meta? LogMeta

fatal(error: unknown, message: string, meta?: LogMeta): void

Emits a record at fatal level.

Pass an error value as the first argument to attach a structured error field assembled via toErrorField.

error unknown

message string

meta? LogMeta

info(message: string, meta?: LogMeta): void

Emits a record at info level.

message string

meta? LogMeta

inject<T extends FlareService>(token: ServiceToken<T>): Injected<T>

Resolves a dependency declared on static deps, returning the service with framework members hidden from its static type.

token ServiceToken<T>

returns Injected<T>

Throws:

When the token is not present in this class’s static deps array.

onStart(): void | Promise<void>

Starts every registered transport in registration order, then flushes the bootstrap buffer.

returns void | Promise<void>

onStop(): void | Promise<void>

Stops every registered transport in reverse registration order.

returns void | Promise<void>

trace(message: string, meta?: LogMeta): void

Emits a record at trace level.

message string

meta? LogMeta

warn(message: string, meta?: LogMeta): void

Emits a record at warn level.

message string

meta? LogMeta

Learn: Logging

Last updated: