콘텐츠로 이동
한국어

JsonLogger

이 콘텐츠는 아직 번역되지 않았습니다.

Defined in: src/Logger.ts:163

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

Each record always carries the four core fields — ts, level, source, and msg — 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', { logger: 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:164

LogLevel = LogLevel.Info

string = ''

LogContextData = {}

JsonLogSink = stdoutSink

JsonLogger

level: LogLevel = LogLevel.Info

Defined in: src/Logger.ts:165

Logger.level

debug(msg, …args): void

Defined in: src/Logger.ts:201

string

unknown[]

void

Logger.debug


error(msg, …args): void

Defined in: src/Logger.ts:204

string

unknown[]

void

Logger.error


info(msg, …args): void

Defined in: src/Logger.ts:202

string

unknown[]

void

Logger.info


warn(msg, …args): void

Defined in: src/Logger.ts:203

string

unknown[]

void

Logger.warn


withFields(fields): Logger

Defined in: src/Logger.ts:210

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:206

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

string

Logger

Logger.withSource