import { LogHook } from "./hooks.js"; /** * A simple logger that can be used to log structured data */ export default class Logger { /** * The function to call to output a JSON line log message */ private readonly out; /** * Base fields that will be included in every log message sent by this logger */ private readonly baseFields; /** * The level this logger is configured to log at */ private readonly logLevel; /** * Any hooks that have been added to this logger */ private readonly hooks; /** * Creates a new logger * @param out The function to call to output the JSON based log message * @param baseFields Any fields to include in every log message * @param hooks Any hooks to apply to every log message */ constructor(out: (obj: unknown) => void, baseFields?: FieldsObject, hooks?: LogHook[]); /** * Trace logs a message at the trace level */ trace(msg: string, fields?: FieldsObject): void; /** * Debug logs a message at the debug level */ debug(msg: string, fields?: FieldsObject): void; /** * Info logs a message at the info level */ info(msg: string, fields?: FieldsObject): void; /** * Warn logs a message at the warn level */ warn(err: Error | unknown, fields?: FieldsObject): void; warn(err: Error | unknown, msg: string, fields?: FieldsObject): void; warn(msg: string, fields?: FieldsObject): void; /** * Error logs a message at the error level */ error(err: Error | unknown, fields?: FieldsObject): void; error(err: Error | unknown, msg: string, fields?: FieldsObject): void; error(msg: string, fields?: FieldsObject): void; /** * Fatal logs a message at the fatal level */ fatal(err: Error, fields?: FieldsObject): void; fatal(err: Error, msg: string, fields?: FieldsObject): void; fatal(msg: string, fields?: FieldsObject): void; /** * with returns a new logger with the given fields added to all log messages * created by it */ with(fields: FieldsObject): Logger; /** * hook returns a new logger with the given hooks applied to all log messages * on top of any existing hooks this logger has */ hook(...newHooks: LogHook[]): Logger; /** * the actual logging implementation */ private log; } /** * A field value we support logging */ export type FieldValue = string | number | boolean | null | undefined | FieldsObject | FieldValue[]; /** * A map of fields that can be logged */ export type FieldsObject = Record;