class ConsoleLogger implements LoggerService {
protected static lastTimestampAt?: number
protected options: ConsoleLoggerOptions
protected context?: string
protected originalContext?: string
protected inspectOptions: InspectOptions
log(message: any, ...optionalParams: any[])
error(message: any, ...optionalParams: any[])
warn(message: any, ...optionalParams: any[])
debug(message: any, ...optionalParams: any[])
verbose(message: any, ...optionalParams: any[])
fatal(message: any, ...optionalParams: any[])
setLogLevels(levels: ("verbose" | "debug" | "log" | "warn" | "error" | "fatal")[])
setContext(context: string)
resetContext()
isLevelEnabled(level: "verbose" | "debug" | "log" | "warn" | "error" | "fatal"): boolean
protected getTimestamp(): string
protected printMessages(messages: unknown[], context: string = '', logLevel: "verbose" | "debug" | "log" | "warn" | "error" | "fatal" = 'log', writeStreamType?: "stdout" | "stderr", errorStack?: unknown)
protected printAsJson(message: unknown, options: { context: string; logLevel: "verbose" | "debug" | "log" | "warn" | "error" | "fatal"; writeStreamType?: "stdout" | "stderr"; errorStack?: unknown; })
protected formatPid(pid: number)
protected formatContext(context: string): string
protected formatMessage(logLevel: "verbose" | "debug" | "log" | "warn" | "error" | "fatal", message: unknown, pidMessage: string, formattedLogLevel: string, contextMessage: string, timestampDiff: string)
protected stringifyMessage(message: unknown, logLevel: "verbose" | "debug" | "log" | "warn" | "error" | "fatal")
protected colorize(message: string, logLevel: "verbose" | "debug" | "log" | "warn" | "error" | "fatal")
protected printStackTrace(stack: string)
protected updateAndGetTimestampDiff(): string
protected formatTimestampDiff(timestampDiff: number)
protected getInspectOptions()
protected stringifyReplacer(key: string, value: unknown)
}
Static properties
Property |
Description |
protected static lastTimestampAt?: number
|
The last timestamp at which the log message was printed.
|
Properties
Property |
Description |
protected options: ConsoleLoggerOptions
|
The options of the logger.
|
protected context?: string
|
The context of the logger (can be set manually or automatically inferred).
|
protected originalContext?: string
|
The original context of the logger (set in the constructor).
|
protected inspectOptions: InspectOptions
|
The options used for the "inspect" method.
|
Methods
log()
|
Write a 'log' level log, if the configured level allows for it.
Prints to stdout with newline.
log(message: any, context?: string): void
Parameters
Option |
Type |
Description |
message
|
any |
|
context
|
string |
Optional. Default is undefined .
|
Returns
void
|
log(message: any, ...optionalParams: any[]): void
Parameters
Option |
Type |
Description |
message
|
any |
|
optionalParams
|
any[] |
|
Returns
void
|
error()
|
Overload #1
Write an 'error' level log, if the configured level allows for it.
Prints to stderr with newline.
error(message: any, stackOrContext?: string): void
Parameters
Option |
Type |
Description |
message
|
any |
|
stackOrContext
|
string |
Optional. Default is undefined .
|
Returns
void
Overload #2
error(message: any, stack?: string, context?: string): void
Parameters
Option |
Type |
Description |
message
|
any |
|
stack
|
string |
Optional. Default is undefined .
|
context
|
string |
Optional. Default is undefined .
|
Returns
void
Overload #3
error(message: any, ...optionalParams: any[]): void
Parameters
Option |
Type |
Description |
message
|
any |
|
optionalParams
|
any[] |
|
Returns
void
|
warn()
|
Write a 'warn' level log, if the configured level allows for it.
Prints to stdout with newline.
warn(message: any, context?: string): void
Parameters
Option |
Type |
Description |
message
|
any |
|
context
|
string |
Optional. Default is undefined .
|
Returns
void
|
warn(message: any, ...optionalParams: any[]): void
Parameters
Option |
Type |
Description |
message
|
any |
|
optionalParams
|
any[] |
|
Returns
void
|
debug()
|
Write a 'debug' level log, if the configured level allows for it.
Prints to stdout with newline.
debug(message: any, context?: string): void
Parameters
Option |
Type |
Description |
message
|
any |
|
context
|
string |
Optional. Default is undefined .
|
Returns
void
|
debug(message: any, ...optionalParams: any[]): void
Parameters
Option |
Type |
Description |
message
|
any |
|
optionalParams
|
any[] |
|
Returns
void
|
verbose()
|
Write a 'verbose' level log, if the configured level allows for it.
Prints to stdout with newline.
verbose(message: any, context?: string): void
Parameters
Option |
Type |
Description |
message
|
any |
|
context
|
string |
Optional. Default is undefined .
|
Returns
void
|
verbose(message: any, ...optionalParams: any[]): void
Parameters
Option |
Type |
Description |
message
|
any |
|
optionalParams
|
any[] |
|
Returns
void
|
fatal()
|
Write a 'fatal' level log, if the configured level allows for it.
Prints to stdout with newline.
fatal(message: any, context?: string): void
Parameters
Option |
Type |
Description |
message
|
any |
|
context
|
string |
Optional. Default is undefined .
|
Returns
void
|
fatal(message: any, ...optionalParams: any[]): void
Parameters
Option |
Type |
Description |
message
|
any |
|
optionalParams
|
any[] |
|
Returns
void
|
setLogLevels()
|
Set log levels
|
setLogLevels(levels: ("verbose" | "debug" | "log" | "warn" | "error" | "fatal")[])
Parameters
Option |
Type |
Description |
levels
|
("verbose" | "debug" | "log" | "warn" | "error" | "fatal")[] |
log levels
|
|
setContext()
|
Set logger context
|
setContext(context: string)
Parameters
Option |
Type |
Description |
context
|
string |
context
|
|
resetContext()
|
Resets the logger context to the value that was passed in the constructor.
|
resetContext()
Parameters
There are no parameters.
|
isLevelEnabled()
|
isLevelEnabled(level: "verbose" | "debug" | "log" | "warn" | "error" | "fatal"): boolean
Parameters
Option |
Type |
Description |
level
|
"verbose" | "debug" | "log" | "warn" | "error" | "fatal" |
|
Returns
boolean
|
getTimestamp()
|
protected getTimestamp(): string
Parameters
There are no parameters.
Returns
string
|
printMessages()
|
protected printMessages(messages: unknown[], context: string = '', logLevel: "verbose" | "debug" | "log" | "warn" | "error" | "fatal" = 'log', writeStreamType?: "stdout" | "stderr", errorStack?: unknown)
Parameters
Option |
Type |
Description |
messages
|
unknown[] |
|
context
|
string |
Optional. Default is '' .
|
logLevel
|
"verbose" | "debug" | "log" | "warn" | "error" | "fatal" |
Optional. Default is 'log' .
|
writeStreamType
|
"stdout" | "stderr" |
Optional. Default is undefined .
|
errorStack
|
unknown |
Optional. Default is undefined .
|
|
printAsJson()
|
protected printAsJson(message: unknown, options: { context: string; logLevel: "verbose" | "debug" | "log" | "warn" | "error" | "fatal"; writeStreamType?: "stdout" | "stderr"; errorStack?: unknown; })
Parameters
Option |
Type |
Description |
message
|
unknown |
|
options
|
object |
|
|
|
protected formatPid(pid: number)
Parameters
Option |
Type |
Description |
pid
|
number |
|
|
formatContext()
|
protected formatContext(context: string): string
Parameters
Option |
Type |
Description |
context
|
string |
|
Returns
string
|
|
protected formatMessage(logLevel: "verbose" | "debug" | "log" | "warn" | "error" | "fatal", message: unknown, pidMessage: string, formattedLogLevel: string, contextMessage: string, timestampDiff: string)
Parameters
Option |
Type |
Description |
logLevel
|
"verbose" | "debug" | "log" | "warn" | "error" | "fatal" |
|
message
|
unknown |
|
pidMessage
|
string |
|
formattedLogLevel
|
string |
|
contextMessage
|
string |
|
timestampDiff
|
string |
|
|
stringifyMessage()
|
protected stringifyMessage(message: unknown, logLevel: "verbose" | "debug" | "log" | "warn" | "error" | "fatal")
Parameters
Option |
Type |
Description |
message
|
unknown |
|
logLevel
|
"verbose" | "debug" | "log" | "warn" | "error" | "fatal" |
|
|
colorize()
|
protected colorize(message: string, logLevel: "verbose" | "debug" | "log" | "warn" | "error" | "fatal")
Parameters
Option |
Type |
Description |
message
|
string |
|
logLevel
|
"verbose" | "debug" | "log" | "warn" | "error" | "fatal" |
|
|
printStackTrace()
|
protected printStackTrace(stack: string)
Parameters
Option |
Type |
Description |
stack
|
string |
|
|
updateAndGetTimestampDiff()
|
protected updateAndGetTimestampDiff(): string
Parameters
There are no parameters.
Returns
string
|
|
protected formatTimestampDiff(timestampDiff: number)
Parameters
Option |
Type |
Description |
timestampDiff
|
number |
|
|
getInspectOptions()
|
protected getInspectOptions()
Parameters
There are no parameters.
|
stringifyReplacer()
|
protected stringifyReplacer(key: string, value: unknown)
Parameters
Option |
Type |
Description |
key
|
string |
|
value
|
unknown |
|
|