Class: Logger
A generalized application logger implementation for Node.JS applications
Constructors
Constructor
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
| Parameter | Type | Default value | Description |
|---|---|---|---|
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. |
meta | Record<string, any> | {} | Additional metadata to include in the log messages. This can be any object. |
options? | LoggerTransportOptions | undefined | Transport options. May contain console and/or loki configuration. |
Returns
Logger
Accessors
complete
Get Signature
get complete(): Promise<void>;A promise that resolves when the logger has finished processing all log messages.
Returns
Promise<void>
Methods
alert()
alert(...args: any[]): void;Log a message with the level of alert
Parameters
| Parameter | Type | Description |
|---|---|---|
...args | any[] | The arguments to log |
Returns
void
child()
child(meta: Record<string, any>): Logger;Return a new logger instance with the same level and additional metadata.
Parameters
| Parameter | Type | Description |
|---|---|---|
meta | Record<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()
close(): void;Close the logger and flush any remaining log messages.
Returns
void
crit()
crit(...args: any[]): void;Log a message with the level of crit
Parameters
| Parameter | Type | Description |
|---|---|---|
...args | any[] | The arguments to log |
Returns
void
debug()
debug(...args: any[]): void;Log a message with the level of debug
Parameters
| Parameter | Type | Description |
|---|---|---|
...args | any[] | The arguments to log |
Returns
void
emerg()
emerg(...args: any[]): void;Log a message with the level of emerg
Parameters
| Parameter | Type | Description |
|---|---|---|
...args | any[] | The arguments to log |
Returns
void
error()
error(...args: any[]): void;Log a message with the level of error
Parameters
| Parameter | Type | Description |
|---|---|---|
...args | any[] | The arguments to log |
Returns
void
info()
info(...args: any[]): void;Log a message with the level of info
Parameters
| Parameter | Type | Description |
|---|---|---|
...args | any[] | The arguments to log |
Returns
void
inspect()
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
| Parameter | Type | Default value | Description |
|---|---|---|---|
arg | unknown | undefined | The 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()
notice(...args: any[]): void;Log a message with the level of notice
Parameters
| Parameter | Type | Description |
|---|---|---|
...args | any[] | The arguments to log |
Returns
void
shutdown()
shutdown(): Promise<void>;Shuts down the logger and flushes any remaining log messages.
Returns
Promise<void>
warning()
warning(...args: any[]): void;Log a message with the level of warning
Parameters
| Parameter | Type | Description |
|---|---|---|
...args | any[] | The arguments to log |
Returns
void
withContext()
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
| Parameter | Type |
|---|---|
context | LogContext |
Returns
Logger
Example
const reqLogger = logger.withContext({ requestId, tenantId, correlationId });
reqLogger.info("checkout intent created");