Logger
class Logger extends FlareServiceStructured 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.
How you get one
Section titled “How you get one”new Logger(transports, container)
Constructor
Section titled “Constructor”new Logger(transports: LoggerTransport[], container: Container): Loggertransports LoggerTransport[]
container Container
Properties
Section titled “Properties”config
Section titled “config”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.
Methods
Section titled “Methods”config()
Section titled “config()”config<T>(token: ConfigToken<T>): TResolves 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()
Section titled “debug()”debug(message: string, meta?: LogMeta): voidEmits a record at debug level.
message string
meta? LogMeta
dispose()
Section titled “dispose()”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>
error()
Section titled “error()”2 overloads
error(message: string, meta?: LogMeta): voidEmits 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): voidEmits 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
fatal()
Section titled “fatal()”2 overloads
fatal(message: string, meta?: LogMeta): voidEmits 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): voidEmits 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()
Section titled “info()”info(message: string, meta?: LogMeta): voidEmits a record at info level.
message string
meta? LogMeta
inject()
Section titled “inject()”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()
Section titled “onStart()”onStart(): void | Promise<void>Starts every registered transport in registration order, then flushes the bootstrap buffer.
returns void | Promise<void>
onStop()
Section titled “onStop()”onStop(): void | Promise<void>Stops every registered transport in reverse registration order.
returns void | Promise<void>
trace()
Section titled “trace()”trace(message: string, meta?: LogMeta): voidEmits a record at trace level.
message string
meta? LogMeta
warn()
Section titled “warn()”warn(message: string, meta?: LogMeta): voidEmits a record at warn level.
message string
meta? LogMeta
Learn: Logging