UNPKG

@naturalcycles/js-lib

Version:

Standard library for universal (browser + Node.js) javascript

55 lines (54 loc) 1.85 kB
import type { MutateOptions } from '../array/array.util.js'; /** * These levels follow console.* naming, * so you can use console[level] safely. * * `log` is considered default level. * * For simplicity - only these 3 levels are kept. * * @experimental */ export type CommonLogLevel = 'log' | 'warn' | 'error'; export declare const commonLogLevelNumber: Record<CommonLogLevel, number>; /** * Function that takes any number of arguments and logs them all. * It is expected that logged arguments are separated by "space", like console.log does. * * @experimental */ export type CommonLogFunction = (...args: any[]) => void; export type CommonLogWithLevelFunction = (level: CommonLogLevel, args: any[]) => void; /** * Interface is inspired/compatible with `console.*` * So, `console` is a valid CommonLogger implementation as-is. * * @experimental */ export interface CommonLogger { log: CommonLogFunction; warn: CommonLogFunction; error: CommonLogFunction; } /** * SimpleLogger that does nothing (noop). * * @experimental */ export declare const commonLoggerNoop: CommonLogger; /** * Creates a "child" logger that is "limited" to the specified CommonLogLevel. */ export declare function commonLoggerMinLevel(logger: CommonLogger, minLevel: CommonLogLevel, opt?: MutateOptions): CommonLogger; /** * Creates a "proxy" CommonLogger that pipes log messages to all provided sub-loggers. */ export declare function commonLoggerPipe(loggers: CommonLogger[]): CommonLogger; /** * Creates a "child" CommonLogger with prefix (one or multiple). */ export declare function commonLoggerPrefix(logger: CommonLogger, ...prefixes: any[]): CommonLogger; /** * Creates a CommonLogger from a single function that takes `level` and `args`. */ export declare function commonLoggerCreate(fn: CommonLogWithLevelFunction): CommonLogger;