UNPKG

@dvcol/common-utils

Version:

Typescript library for common utility functions and constants

146 lines (144 loc) 5.21 kB
declare enum LogLevel { Silent = -1, Error = 0, Warn = 1, Info = 2, Debug = 3, Trace = 4 } /** * Convert a string log level to LogLevel enum * @param logLevel the log level string */ declare const toLogLevel: (logLevel: keyof typeof LogLevel | 'silent' | 'error' | 'warn' | 'info' | 'debug') => LogLevel; declare const TimeStampFormat: { readonly ISO: "ISO"; readonly Date: "Date"; readonly Time: "Time"; readonly Local: "Local"; }; type TimeStampFormats = keyof typeof TimeStampFormat; /** * Generate a logging timestamp * @param scope the logging scope, default to globalThis._proxyLoggerScope * @param format the timestamp format, default to 'TIME' */ declare const getTimestamp: (scope?: string, format?: TimeStampFormats) => string; /** * Logger color constants */ declare const LoggerColor: { readonly Debug: "#9e9e9e"; readonly Info: "#5bd4f9"; readonly Warn: "#f2c61a"; readonly Error: "#ff5549"; readonly Success: "#00ff00"; }; /** * Console format specifiers * @see {@link [Console format specifiers](https://developer.chrome.com/docs/devtools/console/format-style/) } */ declare const ConsoleFormat: { /** * Formats the value as a string * @see ConsoleFormat */ String: string; /** * Formats the value as an integer * @see ConsoleFormat */ Integer: string; /** * Formats the value as a floating point value * @see ConsoleFormat */ Float: string; /** * Formats the value as an expandable DOM element * @see ConsoleFormat */ DOM: string; /** * Formats the value as an expandable JavaScript object * @see ConsoleFormat */ Object: string; /** * Applies CSS style rules to the output string as specified by the second parameter * @see ConsoleFormat */ Style: string; }; declare const colorize: <T extends unknown[]>(color: string, ...args: T) => T; type ProxyLoggerFilter = Partial<Record<keyof Console, (logLevel: LogLevel, ...args: unknown[]) => boolean>>; declare const proxyLoggerFilter: ProxyLoggerFilter; type ProxyLoggerInit<T extends Console = Console> = { proxy?: ProxyLoggerFilter; logger?: T; debug?: boolean | (() => boolean); logLevel?: number | (() => number); timeFormat?: TimeStampFormats | (() => TimeStampFormats); }; /** * Proxy logger to control this extension log level */ declare class ProxyLogger<T extends Console = Console> { private readonly _logger; private readonly _proxy?; private readonly _timeFormat; private readonly _debug; private _logLevel; constructor({ logger, debug, proxy, logLevel, timeFormat, }?: ProxyLoggerInit<T>); get timeFormat(): "ISO" | "Date" | "Time" | "Local"; get isDebug(): boolean; get logLevel(): LogLevel; set logLevel(level: LogLevel); private null; get trace(): Console['trace']; get debug(): Console['debug']; get info(): Console['info']; get warn(): Console['warn']; get error(): Console['error']; static logger: ProxyLogger<Console>; static timestamp: (scope?: string, format?: "ISO" | "Date" | "Time" | "Local") => string; static colorize: <T_1 extends unknown[]>(color: string, ...args: T_1) => T_1; color: { debug: (...args: Parameters<typeof this.debug>) => void; info: (...args: Parameters<typeof this.info>) => void; warn: (...args: Parameters<typeof this.warn>) => void; error: (...args: Parameters<typeof this.error>) => void; success: (...args: Parameters<typeof this.info>) => void; }; /** * Logger with timestamp but looses stack trace origin */ time: { debug: (...args: Parameters<typeof this.debug>) => void; info: (...args: Parameters<typeof this.info>) => void; warn: (...args: Parameters<typeof this.warn>) => void; error: (...args: Parameters<typeof this.error>) => void; color: { debug: (...args: Parameters<typeof this.debug>) => void; info: (...args: Parameters<typeof this.info>) => void; warn: (...args: Parameters<typeof this.warn>) => void; error: (...args: Parameters<typeof this.error>) => void; success: (...args: Parameters<typeof this.info>) => void; }; }; scope: (_scope: string) => { debug: (...args: Parameters<typeof this.debug>) => void; info: (...args: Parameters<typeof this.info>) => void; warn: (...args: Parameters<typeof this.warn>) => void; error: (...args: Parameters<typeof this.error>) => void; color: { debug: (...args: Parameters<typeof this.debug>) => void; info: (...args: Parameters<typeof this.info>) => void; warn: (...args: Parameters<typeof this.warn>) => void; error: (...args: Parameters<typeof this.error>) => void; success: (...args: Parameters<typeof this.info>) => void; }; }; colored: {}; } export { ConsoleFormat, LogLevel, LoggerColor, ProxyLogger, type ProxyLoggerFilter, TimeStampFormat, type TimeStampFormats, colorize, getTimestamp, proxyLoggerFilter, toLogLevel };