Skip to content

Class: Logger ​

A generalized application logger implementation for Node.JS applications

Constructors ​

Constructor ​

ts
new Logger(
   level:
  | LoggerLevel
  | "DEBUG"
  | "INFO"
  | "ERROR"
  | "EMERG"
  | "ALERT"
  | "CRIT"
  | "WARNING"
  | "NOTICE",
   meta: Record<string, any>,
   options?: LoggerTransportOptions): Logger;

Create a new logger instance.

Parameters ​

ParameterTypeDefault valueDescription
level| LoggerLevel | "DEBUG" | "INFO" | "ERROR" | "EMERG" | "ALERT" | "CRIT" | "WARNING" | "NOTICE"'info'The log level to use. This can be any of the levels defined in LoggerLevel.
metaRecord<string, any>{}Additional metadata to include in the log messages. This can be any object.
options?LoggerTransportOptionsundefinedTransport options. May contain console and/or loki configuration.

Returns ​

Logger

Accessors ​

complete ​

Get Signature ​

ts
get complete(): Promise<void>;

A promise that resolves when the logger has finished processing all log messages.

Returns ​

Promise<void>

Methods ​

alert() ​

ts
alert(...args: any[]): void;

Log a message with the level of alert

Parameters ​

ParameterTypeDescription
...argsany[]The arguments to log

Returns ​

void


child() ​

ts
child(meta: Record<string, any>): Logger;

Return a new logger instance with the same level and additional metadata.

Parameters ​

ParameterTypeDescription
metaRecord<string, any>Additional metadata to include in the log messages. This can be any object.

Returns ​

Logger

A new logger instance with the same level and additional metadata.


close() ​

ts
close(): void;

Close the logger and flush any remaining log messages.

Returns ​

void


crit() ​

ts
crit(...args: any[]): void;

Log a message with the level of crit

Parameters ​

ParameterTypeDescription
...argsany[]The arguments to log

Returns ​

void


debug() ​

ts
debug(...args: any[]): void;

Log a message with the level of debug

Parameters ​

ParameterTypeDescription
...argsany[]The arguments to log

Returns ​

void


emerg() ​

ts
emerg(...args: any[]): void;

Log a message with the level of emerg

Parameters ​

ParameterTypeDescription
...argsany[]The arguments to log

Returns ​

void


error() ​

ts
error(...args: any[]): void;

Log a message with the level of error

Parameters ​

ParameterTypeDescription
...argsany[]The arguments to log

Returns ​

void


info() ​

ts
info(...args: any[]): void;

Log a message with the level of info

Parameters ​

ParameterTypeDescription
...argsany[]The arguments to log

Returns ​

void


inspect() ​

ts
inspect(arg: unknown, level:
  | LoggerLevel
  | "DEBUG"
  | "INFO"
  | "ERROR"
  | "EMERG"
  | "ALERT"
  | "CRIT"
  | "WARNING"
  | "NOTICE"): void;

Log an inspected value using the Node.js util.inspect function.

Parameters ​

ParameterTypeDefault valueDescription
argunknownundefinedThe value to inspect.
level| LoggerLevel | "DEBUG" | "INFO" | "ERROR" | "EMERG" | "ALERT" | "CRIT" | "WARNING" | "NOTICE"'info'The log level to use. This can be any of the levels defined in LoggerLevel.

Returns ​

void


notice() ​

ts
notice(...args: any[]): void;

Log a message with the level of notice

Parameters ​

ParameterTypeDescription
...argsany[]The arguments to log

Returns ​

void


shutdown() ​

ts
shutdown(): Promise<void>;

Shuts down the logger and flushes any remaining log messages.

Returns ​

Promise<void>


warning() ​

ts
warning(...args: any[]): void;

Log a message with the level of warning

Parameters ​

ParameterTypeDescription
...argsany[]The arguments to log

Returns ​

void


withContext() ​

ts
withContext(context: LogContext): Logger;

Return a new logger instance carrying the supplied LogContext fields on every record. Equivalent to Logger.child but typed against the standard structured-context fields (correlationId, requestId, tenantId, traceId, spanId, userId, module).

Prefer this over Logger.child for cross-cutting observability fields so the field names stay consistent across services.

Parameters ​

ParameterType
contextLogContext

Returns ​

Logger

Example ​

ts
const reqLogger = logger.withContext({ requestId, tenantId, correlationId });
reqLogger.info("checkout intent created");