Перейти к содержимому
Русский

JsonLogger

Это содержимое пока не доступно на вашем языке.

Defined in: src/Logger.ts:202

Structured-logging logger that emits one \n-delimited JSON object per record to process.stdout (or an injected JsonLogSink).

Each record always carries ts, level, and msg; source is emitted only when one is bound (via withSource). These are followed by the merged static + dynamic MDC (static from withFields, dynamic from LogContext.run, with dynamic winning on key collision to match the “innermost scope wins” intuition). Extra positional ...args from log.info(msg, extra1, extra2) go under an args array; the common shape log.info('processed', { items: 42 }) simply puts {items:42} into args[0] so log aggregators can index nested keys.

Wire it in at system construction:

const system = ActorSystem.create('my-app', ActorSystemOptions.create().withLogger(new JsonLogger()));

Output (one line, line-wrapped here for readability):

{"ts":"2026-05-14T12:34:56.789Z","level":"info",
"source":"actor-ts://my-app/user/order",
"msg":"placing order",
"correlationId":"abc-123","userId":"user-42",
"args":[{"items":42}]}

No pretty-printing, no colour codes, no level-prefix shorthand — machine-readable by design. For human-readable text logs use the default ConsoleLogger; for OTel-pipeline ingestion bridge a JsonLogger-equivalent via otelLogger({ api }).

Error rendering. Pass an Error and the logger serialises name, message, and stack (the bare object would otherwise become "{}" because Error’s own enumerable surface is empty).

JSON-safety. Values are sent through JSON.stringify with a replacer that handles BigInt, circular references, and undefined/function values gracefully — a log call never throws.

new JsonLogger(level?, source?, staticFields?, sink?): JsonLogger

Defined in: src/Logger.ts:203

LogLevel = LogLevel.Info

string = ''

LogContextData = {}

JsonLogSink = stdoutSink

JsonLogger

level: LogLevel = LogLevel.Info

Defined in: src/Logger.ts:204

Logger.level

debug(message, …args): void

Defined in: src/Logger.ts:240

string

…unknown[]

void

Logger.debug


error(message, …args): void

Defined in: src/Logger.ts:243

string

…unknown[]

void

Logger.error


info(message, …args): void

Defined in: src/Logger.ts:241

string

…unknown[]

void

Logger.info


warn(message, …args): void

Defined in: src/Logger.ts:242

string

…unknown[]

void

Logger.warn


withFields(fields): Logger

Defined in: src/Logger.ts:249

Create a logger with extra static fields baked in. Unlike LogContext (which is dynamic / per-async-stack), withFields stamps the same fields on every record this logger emits — handy for component-level tagging like { component: 'shard-coordinator' } or { shardId: 12 } on a per-entity logger.

LogContextData

Logger

Logger.withFields


withSource(source): Logger

Defined in: src/Logger.ts:245

Create a logger bound to a source (e.g. an actor path).

string

Logger

Logger.withSource