import { AnyRecord, Falsy } from "@neodx/std"; //#region src/core/types.d.ts /** * Representing log methods. All log methods must implement this interface. */ interface LoggerMethod { (target: T, message?: string, ...args: unknown[]): void; (target: unknown, message?: string, ...args: unknown[]): void; (message: string, ...args: unknown[]): void; } /** * Custom transformer function that will receive log chunks before they are passed to streams. */ interface LoggerTransformer { (chunk: LogChunk): LogChunk; } interface LoggerHandler { (chunk: LogChunk): void | Promise; } interface LoggerHandleConfig { /** * The minimum level priority that this stream will receive. * @example 'info' - will receive 'info', 'warn' and 'error' chunks * @example 'warn' - will receive 'warn' and 'error' chunks * @example 'error' - will receive only 'error' chunks * @default no minimum level, will receive all chunks */ level?: Level; /** * Your handler function(s) that will receive log chunks. * @example (chunk) => console.log(chunk) * @example (chunk) => Promise.resolve(console.log(chunk)) */ target: LoggerHandler | LoggerHandler[]; } interface LogChunk { /** * The name of the logger that created this chunk. * @example 'my-app' * @example 'my-app:my-module' */ name: string; /** * The date that this chunk was created. */ date: Date; /** * The level of this chunk. * @example 'info' * @example 'warn' */ level: Level; /** * The error that was passed as first argument to the log method (usually at `error` level). */ error?: Error; /** * Object with additional fields that were passed to the log method. * @example { pid: 1234, hostname: 'my-host' } * @example { headers: { 'x-request-id': '1234' } } */ meta: LoggerBaseMeta; /** * Pre-formatted message. */ msg: string; msgArgs?: unknown[]; msgTemplate?: string; /** * @internal */ __: Readonly & Record>; } interface LoggerInternals { /** * Dictionary of log levels with priority (lower is more prioritized). * @default { error: 10, warn: 20, info: 30, verbose: 40, debug: 50, silent: Infinity } */ levels: LoggerLevelsConfig; originalLevel: Level; } type LoggerLevelsConfig = Record; type LoggerBaseMeta = Record; type LoggerMethods = Record; type Logger = { readonly meta: LoggerBaseMeta; fork

>(params?: Partial

): Logger; fork(params: LoggerParamsWithLevels): Logger>; child

>(name: string, params?: Partial>): Logger; child(name: string, params: Omit, 'name'>): Logger>; } & LoggerMethods; interface CreateLogger { (params: LoggerParamsWithLevels): Logger>; (params?: Partial>): Logger; } interface LoggerParamsWithLevels extends Partial>> { /** * Dictionary of log levels with priority (lower is more prioritized). * The higher the number, the less important the level and the more likely it will be ignored. * @default { error: 10, warn: 20, info: 30, verbose: 40, debug: 50 } * @example { foo: 10, bar: 20, baz: 30 } - custom levels, where 'foo' is the most important and 'baz' is the least important */ levels: LevelsConfig; } interface LoggerParams { /** * Logger name will be shown in the logs. * @example 'my-app' * @example 'my-app:my-module' */ name: string; /** * The logging level, everything higher than this level will be ignored. * @example 'info' * @example 'verbose' */ level: Level; /** * Additional fields that will be added to every log chunk. */ meta: LoggerBaseMeta; /** * List of streams that will receive log chunks. * @example [{ level: 'info', target: [console.log] }, { level: 'error', target: [console.error] }] * @example [{ level: 'info', target: console.log }, { level: 'error', target: console.error }] * @example [console.log] * @example console.log * @example { level: 'info', target: console.log } * @example { level: 'info', target: [console.log] } * @example { level: 'info', target: [{ write: console.log }] } */ target: LoggerHandler | LoggerHandleConfig | Array | LoggerHandleConfig | Falsy>; transform: LoggerTransformer | LoggerTransformer[]; } type BaseLevelsConfig = LoggerLevelsConfig; type GetLevelNames = Extract; //#endregion //#region src/utils/create-auto-logger-factory.d.ts declare const createLoggerAutoFactory: (factory: CreateLogger) => (log: AutoLoggerInput, defaultParams?: Partial>) => Logger; type AutoLoggerInput = Level | (Partial> & Pick, 'level'>) | 'silent' | Logger; //#endregion //#region src/utils/printf.d.ts /** * Tiny implementation of printf function. * Supports only "%s" (string) and "%d" (number). * @see https://github.com/floatdrop/pff * @example printf('%s in %ds.', ['Done', 12]) => "Done on 12s." */ declare function printf(template: string, replaces: unknown[]): string; //#endregion //#region src/utils/read-arguments.d.ts 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; //#endregion //#region src/utils/serialize-json.d.ts /** * Safe version of JSON.stringify, prevents circular refs * @example serializeJSON({ record: { value: 1, name: 'age' }, valid: false }) */ declare const serializeJSON: (value: unknown, space?: string | number) => string; //#endregion export { LoggerMethod as _, AutoLoggerInput as a, LoggerParamsWithLevels as b, CreateLogger as c, Logger as d, LoggerBaseMeta as f, LoggerLevelsConfig as g, LoggerInternals as h, printf as i, GetLevelNames as l, LoggerHandler as m, LogArguments as n, createLoggerAutoFactory as o, LoggerHandleConfig as p, readArguments as r, BaseLevelsConfig as s, serializeJSON as t, LogChunk as u, LoggerMethods as v, LoggerTransformer as x, LoggerParams as y }; //# sourceMappingURL=index-Cfc0Li7l.d.mts.map