@naturalcycles/js-lib
Version:
Standard library for universal (browser + Node.js) javascript
58 lines (57 loc) • 2.07 kB
TypeScript
import type { MutateOptions } from '../types.js';
/**
* These levels follow console.* naming,
* so you can use console[level] safely.
*
* `debug` is not enabled by default, and is useful when debugging is needed.
*
* `log` is considered default level, and is enabled by default.
*
* `warn` is for warnings - things that are not super-severe to be an error, but should not happen
*
* `error` level would only log errors
*
* @experimental
*/
export type CommonLogLevel = 'debug' | '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 {
debug: CommonLogFunction;
log: CommonLogFunction;
warn: CommonLogFunction;
error: CommonLogFunction;
}
/**
* SimpleLogger that does nothing (noop).
*/
export declare const commonLoggerNoop: CommonLogger;
/**
* Creates a "child" logger that is "limited" to the specified CommonLogLevel.
*/
export declare function createCommonLoggerAtLevel(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;