Skip to content

LoggerTransport

class LoggerTransport extends FlareBase

Abstract base class for all Flare log transports.

A transport is an outbound destination that receives fully assembled LogRecord objects from the logger and decides what to do with them: format, serialize, transmit.

Extends FlareBase so transports can declare static deps and access this.config(). Transports are managed by the logger, not the host singleton lifecycle directly. Their onStart and onStop hooks are called by the logger during its own lifecycle.

Declare a static transportName property matching the key used in flare.json under log.transports for per-transport level filtering.

new LoggerTransport()

new LoggerTransport(): LoggerTransport
config: readonly ConfigToken<unknown>[]

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: never[]

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.

transportName: string
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.

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

Always throws: transports cannot inject services; use onStart() and this.config().

token ServiceToken<T>

returns T

onStart(): void | Promise<void>

returns void | Promise<void>

onStop(): void | Promise<void>

returns void | Promise<void>

write(record: LogRecord): void

Receives one fully assembled record; the transport decides how to format and emit it.

record LogRecord

Learn: Custom transports

Last updated: