UNPKG

@augment-vir/common

Version:

A collection of augments, helpers types, functions, and classes for any JavaScript environment.

61 lines (60 loc) 1.93 kB
import { type PartialWithUndefined } from '@augment-vir/core'; import { LogColorKey } from './log-colors.js'; import { type LoggerOptions } from './log-string.js'; import { type LogWriters } from './log-writer.js'; /** * The base `log` methods. * * @category Log : Util * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export type LoggerLogs = Readonly<Record<LogColorKey, (...args: ReadonlyArray<unknown>) => void>>; /** * Type for the `log` export. * * @category Log : Util * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export type Logger = LoggerLogs & { /** * Only logs if the given condition is `true`. * * @example * * ```ts * import {log} from '@augment-vir/common'; * * // this will log * log.if(true).info('hi'); * // this will not log * log.if(false).info('hi'); * ``` */ if: (condition: boolean) => LoggerLogs; }; /** * Default implementation of {@link LoggerOptions}. * * @category Log : Util * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export declare const defaultLoggerOptions: LoggerOptions; /** * A default {@link Logger} that simply does nothing. * * @category Log * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export declare const emptyLog: Logger; /** * Creates a custom {@link Logger}. * * @category Log * @category Package : @augment-vir/common * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common) */ export declare function createLogger(logWriters: LogWriters, optionsOverride?: PartialWithUndefined<LoggerOptions> | undefined): Logger;