Skip to content

CfLoggerTransport

class CfLoggerTransport extends LoggerTransport

Abstract base for log transports running under CfLogger.

Narrows onStart and onStop to synchronous return types so the Cloudflare logger can drive lifecycle without awaiting promises. An async override still typechecks (TS treats a Promise return as assignable to void) but its promise is never awaited: overrides must complete synchronously.

new CfLoggerTransport()

new CfLoggerTransport(): CfLoggerTransport
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
onStop(): 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: