import { WithCaller } from "./internal/hooks"; import Logger from "./internal/logger"; import globals from "./internal/globals"; import type { FieldsObject } from "./internal/logger"; export type { FieldsObject } from "./internal/logger"; export type { Logger }; /* eslint-disable @typescript-eslint/unified-signatures */ const log: Logger = new Logger( (obj: unknown) => { globals.Runtime.objToStderr(obj); }, undefined, [WithCaller()], ); /** * The default logger for the app */ export default log; /** * Trace logs a message at the trace level */ export function trace(msg: string, fields?: FieldsObject) { log.trace(msg, fields); } /** * Debug logs a message at the debug level */ export function debug(msg: string, fields?: FieldsObject) { log.debug(msg, fields); } /** * Info logs a message at the info level */ export function info(msg: string, fields?: FieldsObject) { log.info(msg, fields); } /** * Warn logs a message at the warn level */ export function warn(err: Error | unknown, fields?: FieldsObject): void; export function warn( err: Error | unknown, msg: string, fields?: FieldsObject, ): void; export function warn(msg: string, fields?: FieldsObject): void; export function warn( errOrMsg: unknown, msgOrFields: unknown, fields?: unknown, ) { // the type cast here is just for TSC to be happy - the underlying method uses the same overloads so // will type check the arguments correctly log.warn( errOrMsg as Error, msgOrFields as string, fields as FieldsObject | undefined, ); } /** * Error logs a message at the error level */ export function error(err: Error | unknown, fields?: FieldsObject): void; export function error( err: Error | unknown, msg: string, fields?: FieldsObject, ): void; export function error(msg: string, fields?: FieldsObject): void; export function error( errOrMsg: unknown, msgOrFields: unknown, fields?: unknown, ) { // the type cast here is just for TSC to be happy - the underlying method uses the same overloads so // will type check the arguments correctly log.error( errOrMsg as Error, msgOrFields as string, fields as FieldsObject | undefined, ); } /** * Fatal logs a message at the fatal level */ export function fatal(err: Error | unknown, fields?: FieldsObject): void; export function fatal( err: Error | unknown, msg: string, fields?: FieldsObject, ): void; export function fatal(msg: string, fields?: FieldsObject): void; export function fatal( errOrMsg: unknown, msgOrFields: unknown, fields?: unknown, ) { // the type cast here is just for TSC to be happy - the underlying method uses the same overloads so // will type check the arguments correctly log.fatal( errOrMsg as Error, msgOrFields as string, fields as FieldsObject | undefined, ); }