import { Integer } from '@epdoc/typeutil'; import { AppTimer } from './apptimer'; import { Style, StyleDef, StyleName, StyleOptions } from './style'; export declare const logLevel: { readonly trace: 1; readonly debug: 3; readonly verbose: 5; readonly info: 7; readonly warn: 8; readonly error: 9; }; export type LogLevel = keyof typeof logLevel; export type LogLevelValue = (typeof logLevel)[LogLevel]; /** * Checks if the given value is a valid LogLevel. * @param {any} val - The value to check. * @returns {boolean} True if the value is a valid LogLevel, false otherwise. */ export declare function isLogLevelValue(val: any): val is LogLevelValue; export type TimePrefix = 'local' | 'utc' | 'elapsed' | false; export declare function isValidTimePrefix(val: any): val is TimePrefix; /** * Configuration options for the Logger. * @typedef {Object} LoggerOptions * @property {boolean} [enableStyles] - Whether to enable styling of console messages. Defaults to false. * @property {Style} [style] - Custom Style instance to use for formatting. Defaults to the default style. * @property {LogLevel | LogLevelValue} [level] - The minimum log level to output. * @property {Integer} [tab] - The number of spaces to use for indentation. Defaults to 2. * @property {boolean} [levelPrefix] - Whether to prefix log messages with their level. Defaults to false. * @property {TimePrefix} [timePrefix] - The type of time prefix to use ('local', 'utc', 'elapsed', or false). Defaults to false. * @property {AppTimer} [elapsed] - Custom Elapsed instance for tracking time. Defaults to the elapsed time object. * @property {boolean} [keepLines] - Whether to keep log lines in memory instead of outputting immediately. Defaults to false. */ export type LoggerOptions = StyleOptions & { enableStyles?: boolean; style?: Style; level?: LogLevel | LogLevelValue; tab?: Integer; levelPrefix?: boolean; timePrefix?: TimePrefix; appTimer?: AppTimer; keepLines?: boolean; }; /** * Logger class * @example * ```typescript * const log:LoggerInstance = new Logger(); * log.info('Hello, world!'); * ``` */ export declare class Logger { protected _style: Style; protected _level: LogLevelValue; protected _tab: Integer; protected _levelPrefix: boolean; protected _timePrefix: TimePrefix; protected _appTimer: AppTimer; protected _pre: string[]; protected _showElapsed: boolean; protected _keepLines: boolean; protected _lines: any[]; [key: string]: ((val: any) => this) | any; /** * Constructor for the Logger class. * @param {LoggerOptions} options - The options for the logger. */ constructor(options?: LoggerOptions); /** * Sets an alternate style for the logger. * @param {Style} style - The style to set. */ setStyle(style: Style): this; /** * Gets the current style. * @returns {Style} The current style. */ get style(): Style; /** * Gets the lines stored in memory. Only applicable if keepLines is true. * @returns {string[]} The lines stored in memory. */ get lines(): string[]; /** * Sets the log level. * @param {LogLevel | 'trace' | 'debug' | 'verbose' | 'info' | 'error'} level - The log level to set. * @returns {this} The Logger instance. */ setLevel(level: LogLevel | LogLevelValue): this; /** * Gets the current log level. * @returns {LogLevel} The current log level. */ get level(): LogLevelValue; /** * Sets whether to include a prefix with the log level. * @param {boolean} val - Whether to include a prefix with the log level. * @returns {this} The Logger instance. */ setLevelPrefix(val: boolean): this; /** * Sets the number of spaces to use for indentation. * @param {Integer} val - The number of spaces to use for indentation. * @returns {this} The Logger instance. */ setTab(val: Integer): this; /** * Sets the time prefix. * @param {TimePrefix} val - The time prefix to set. * @returns {this} The Logger instance. */ setTimePrefix(val: TimePrefix): this; /** * Sets the elapsed time object. * @param {AppTimer} val - The elapsed time object to set. * @returns {this} The Logger instance. */ setAppTimer(val: AppTimer): this; /** * Sets whether to keep lines in memory rather than outputting them immediately to the console. * @param {boolean} val - Whether to keep lines in memory. * @returns {this} The Logger instance. */ setKeepLines(val: boolean): this; /** * Checks if the logger is enabled for the given log level. This can eliminate * running logging code if the log level is not enabled and the logging would * not be output anyway. * @param {LogLevel} val - The log level to check. * @returns {boolean} True if the logger is enabled for the given level, false * otherwise. */ isEnabledFor(val: LogLevel | LogLevelValue): boolean; /** * Enables elapsed time logging for this line of output, which will result in * the elapsed time being output at the end the log line. * @returns {this} The Logger instance. * @throws {Error} If elapsed time logging is already enabled. */ elapsed(): this; clearLines(): this; /** * Clears the logger's internal state, essentially resetting the output line. * @returns {this} The Logger instance. */ clearLine(): this; /** * Adds stringified data to the log message. This text will be formatted with * the default style. * @param {any} arg - The data to stringify and add. * @returns {this} The Logger instance. */ data(arg: any): this; /** * Indents the log message by this many characters or the string to indent with. * @param {Integer | string} n - The number of spaces to indent or the string to indent with. * @returns {this} The Logger instance. */ indent(n?: Integer | string): this; /** * Adds indented text to the log message. * @param {Integer} n - The number of tabs by which to indent. * @returns {this} The Logger instance. */ tab(n?: Integer): this; /** * Adds indented text to the log message. 'res' stands for 'response', and * might be used to indent the response to an action. * @param {...any[]} args - The text arguments to add. * @returns {this} The Logger instance. * @deprecated Use indent() instead. */ res(...args: any[]): this; /** * Adds double-indented text to the log message. * @param {...any[]} args - The text arguments to add. * @returns {this} The Logger instance. * @deprecated Use indent() instead. */ res2(...args: any[]): this; /** * Adds styled text to the log message. * @param {any} val - The value to style. * @param {StyleName | StyleDef} style - The style to use. * @returns {this} The Logger instance. */ stylize(style: StyleName | StyleDef, ...args: any[]): this; /** * Adds our dynamic style methods to the logger instance. * @returns {void} */ addStyleMethods(): this; /** * Outputs a trace level log message if the current log level allows it. * @param {...any[]} args - The message arguments to log. * @returns {this} The Logger instance. */ trace(...args: any[]): this; /** * Outputs a debug level log message if the current log level allows it. * @param {...any[]} args - The message arguments to log. * @returns {this} The Logger instance. */ debug(...args: any[]): this; /** * Outputs a verbose level log message if the current log level allows it. * @param {...any[]} args - The message arguments to log. * @returns {this} The Logger instance. */ verbose(...args: any[]): this; /** * Outputs an info level log message if the current log level allows it. * @param {...any[]} args - The message arguments to log. * @returns {this} The Logger instance. */ info(...args: any[]): this; /** * Outputs a warn level log message if the current log level allows it. * @param {...any[]} args - The message arguments to log. * @returns {this} The Logger instance. */ warn(...args: any[]): this; /** * Outputs an error level log message if the current log level allows it. * @param {...any[]} args - The message arguments to log. * @returns {this} The Logger instance. */ error(...args: any[]): this; protected addPrefix(level: string): this; /** * Outputs the log message. * @param {...any[]} args - The message arguments to log. * @returns {this} The Logger instance. */ output(...args: any[]): this; /** * Placeholder method for skipping log messages. * @param {any} val - The value to potentially skip. * @returns {boolean} Always returns false in this implementation. */ skip(val: any): boolean; } export type LoggerInstance = Logger & Record Logger>;