Clarify documentation for flattenMessage.

This commit is contained in:
2025-12-15 12:26:09 -06:00
parent f33ca24b53
commit 4ddeeab228

View File

@@ -34,12 +34,15 @@ export interface LogMessage {
export type FlattenedLogMessage = Record<string, unknown>; export type FlattenedLogMessage = Record<string, unknown>;
/** /**
* Flatten a log message to a plain object. The *message* field can be either a * Flatten a log message to a plain object in preparation for emission to an
* string or an object. In the case of an object message, the LogMessage should * appender.
* be flattened before being emitted by an appender, promoting the object's *
* fields to the top level of the message. Fields defined on the *LogMessage* * In general, the *message* field can be either a string or an object. In the
* interface are reserved and should not be used as keys in the message object * case of an object message, the LogMessage should be flattened before being
* (and will be ignored if they are). * emitted by an appender, promoting the object's fields to the top level of
* the message. Fields defined on the *LogMessage* interface are reserved and
* should not be used as keys in the message object (and will be ignored if
* they are).
* *
* So, for example: * So, for example:
* *
@@ -48,7 +51,7 @@ export type FlattenedLogMessage = Record<string, unknown>;
* logger.info({ foo: 'bar', baz: 'qux', ts: 'today', level: LogLevel.WARN }); * logger.info({ foo: 'bar', baz: 'qux', ts: 'today', level: LogLevel.WARN });
* ``` * ```
* *
* Should result after flattening in a structured log message like: * Will result in a structured log message after flattening like:
* ```json * ```json
* {"scope":"example","level":"INFO","foo":"bar","baz":"qux","ts":"2020-01-01T00:00:00.000Z"} * {"scope":"example","level":"INFO","foo":"bar","baz":"qux","ts":"2020-01-01T00:00:00.000Z"}
* ``` * ```