Logger
Represents a logger utility for logging messages with various log levels.
Signature
export declare class LoggerProperties
21Methods
12Properties
readonly options: Required<LoggerOptions>;The options for configuring the logger.
static saveOnFile?: string[] | 'all';static dirname: string;private static streams;private static fileNames;private static createdDir?;private static __assignFileName;private static __memoryCache;The custom callback function for logging.
private static __callback;levelSetterset level(level: LogLevels);Sets the log level of the logger. Gets the log level of the logger.
levelGetterget level(): LogLevels;Sets the log level of the logger. Gets the log level of the logger.
saveOnFileSetterset saveOnFile(saveOnFile: boolean);saveOnFileGetterget saveOnFile(): boolean;activeSetterset active(active: boolean);Sets whether the logger is active or not. Gets whether the logger is active or not.
activeGetterget active(): boolean;Sets whether the logger is active or not. Gets whether the logger is active or not.
nameSetterset name(name: string);Sets the name of the logger. Gets the name of the logger.
nameGetterget name(): string;Sets the name of the logger. Gets the name of the logger.
private __write;static DEFAULT_OPTIONS: Required<LoggerOptions>;The default options for 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.
cb- The custom callback function for logging.
A disposer that restores the previous callback (no-op if a newer one replaced it).
Logger.customize((logger, level, args) => {
// Custom logging implementation
});static getCustomizer(): CustomizeLoggerCallback;Returns the current logging callback, so a customizer can chain the previous one.
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.
cb- A function that takes the logger instance and returns a string representing the customized filename for the log.
Logger.customizeFilename((logger) => {
return `${logger.name}-${Date.now()}.log`;
});static clearLogs(): Promise<void>;constructorConstructorconstructor(options: LoggerOptions);rawLog(level: LogLevels, ...args: unknown[]): void;Logs a message with the specified log level.
level- The log level.
args- The arguments to log.
The logged message.
debug(...args: any[]): void;Logs a debug message.
args- The arguments to log.
info(...args: any[]): void;Logs an info message.
args- The arguments to log.
warn(...args: any[]): void;Logs a warning message.
args- The arguments to log.
error(...args: any[]): void;Logs an error message.
args- The arguments to log.
fatal(...args: any[]): void;Logs a fatal error message.
args- The arguments to log.
static noColor(msg: string): string;A function that returns the input string as is, without any color modification.
msg- The message to log.
The input message as is.