Logger

Represents a logger utility for logging messages with various log levels.

Signature

export declare class Logger

Properties

private static __memoryCache;

The custom callback function for logging.

levelSetter
set level(level: LogLevels);

Sets the log level of the logger. Gets the log level of the logger.

levelGetter
get level(): LogLevels;

Sets the log level of the logger. Gets the log level of the logger.

activeSetter
set active(active: boolean);

Sets whether the logger is active or not. Gets whether the logger is active or not.

activeGetter
get active(): boolean;

Sets whether the logger is active or not. Gets whether the logger is active or not.

nameSetter
set name(name: string);

Sets the name of the logger. Gets the name of the logger.

nameGetter
get name(): string;

Sets the name of the logger. Gets the name of the logger.

static colorFunctions: Map<LogLevels, (str: string) => string>;

A map containing color functions for different log levels.

static prefixes: Map<LogLevels, string>;

A map containing prefixes for different log levels.

Methods

static customize(cb: CustomizeLoggerCallback): () => void;

Allows customization of the logging behavior by providing a custom callback function.

Parameters
cb
The custom callback function for logging.
Returns

A disposer that restores the previous callback (no-op if a newer one replaced it).

Examples
Logger.customize((logger, level, args) => {
    // Custom logging implementation
});
static customizeFilename(cb: AssignFilenameCallback): void;

Customizes the logging filename by providing a callback function. The callback receives the logger instance and should return the desired filename.

Parameters
cb
A function that takes the logger instance and returns a string representing the customized filename for the log.
Examples
Logger.customizeFilename((logger) => {
    return `${logger.name}-${Date.now()}.log`;
});
rawLog(level: LogLevels, ...args: unknown[]): void;

Logs a message with the specified log level.

Parameters
level
The log level.
args
The arguments to log.
Returns

The logged message.

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

Logs a debug message.

Parameters
args
The arguments to log.
info(...args: any[]): void;

Logs an info message.

Parameters
args
The arguments to log.
warn(...args: any[]): void;

Logs a warning message.

Parameters
args
The arguments to log.
error(...args: any[]): void;

Logs an error message.

Parameters
args
The arguments to log.
fatal(...args: any[]): void;

Logs a fatal error message.

Parameters
args
The arguments to log.
static noColor(msg: string): string;

A function that returns the input string as is, without any color modification.

Parameters
msg
The message to log.
Returns

The input message as is.