UNPKG

@neodx/log

Version:

A lightweight universal logging framework

46 lines (42 loc) 1.89 kB
import { C as CreateLogger, a as LoggerParams, b as Logger } from './types-Co7FibqF.js'; import { AnyRecord } from '@neodx/std'; declare const createLoggerAutoFactory: ( factory: CreateLogger<any> ) => <const Level extends string>( log: AutoLoggerInput<Level>, defaultParams?: Partial<LoggerParams<Level>> | undefined ) => Logger<Level>; type AutoLoggerInput<Level extends string> = | Level | (Partial<LoggerParams<Level>> & Pick<LoggerParams<Level>, 'level'>) | 'silent' | Logger<Level>; type LogArguments = [messageFragments: unknown[], meta: AnyRecord, error?: Error]; /** * Reads arguments array and extract fields, error and message arguments. * @return [messageFragments, fields, error] * * Strings * @example readArguments('hello') -> [ ['hello'], {} ] * @example readArguments('hello %s', 'world') -> [ ['hello %s', 'world'], {} ] * @example readArguments('hello %s %d %j', 'world', 1, { id: 2 }) -> [ ['hello %s %d %j', 'world', 1, { id: 2 }], {} ] * * Additional fields * @example readArguments({ id: 2 }) -> [ [], { id: 2 } ] * @example readArguments({ id: 2 }, 'hello') -> [ ['hello'], { id: 2 } ] * @example readArguments({ id: 2 }, 'hello %s', 'world') -> [ ['hello %s', 'world'], { id: 2 } ] * * Errors * @example readArguments(myError) -> [ ['my error'], {}, myError ] * @example readArguments({ err: myError }) -> [ ['my error'], {}, myError ] * @example readArguments({ err: myError, id: 2 }) -> [ ['my error'], { id: 2 }, myError ] * @example readArguments({ err: myError, id: 2 }, 'hello') -> [ ['hello'], { id: 2 }, myError ] * @example readArguments({ err: myError, id: 2 }, 'hello %s', 'world') -> [ ['hello %s', 'world'], { id: 2 }, myError ] */ declare function readArguments(args: unknown[]): LogArguments; export { type AutoLoggerInput as A, type LogArguments as L, createLoggerAutoFactory as c, readArguments as r };