UNPKG

@mojojs/core

Version:

Real-time web framework

141 lines (140 loc) 3.25 kB
import type { WriteStream } from 'node:fs'; interface LogContext { requestId?: string; [key: string]: any; } interface LogEvent extends LogContext { level: string; time: string; msg: string; } type LogFormatter = (data: LogEvent) => string; /** * A simple logger class. */ export declare class Logger { /** * Log destination stream. */ destination: NodeJS.WritableStream; /** * Log formatter. */ formatter: LogFormatter; /** * The last few logged messages. */ history: LogEvent[]; _capture: CapturedLogs | undefined; _historySize: number | undefined; _level: number; constructor(options?: { destination?: WriteStream; formatter?: LogFormatter; historySize?: number; level?: string; }); /** * Capture log messages for as long as the returned object has not been stopped, useful for testing log messages. */ capture(level?: string): CapturedLogs; /** * Create a child logger that will include context information with every log message. */ child(context: LogContext): ChildLogger; /** * Log formatter with color highlighting. */ static colorFormatter(data: LogEvent): string; /** * Log `debug` message. */ debug(msg: string, context?: LogContext): void; /** * Log formatter without color highlighting. */ static stringFormatter(data: LogEvent): string; /** * Log formatter for systemd. */ static systemdFormatter(data: LogEvent): string; /** * Log `error` message. */ error(msg: string, context?: LogContext): void; /** * Log `fatal` message. */ fatal(msg: string, context?: LogContext): void; /** * Log `infor` message. */ info(msg: string, context?: LogContext): void; /** * JSON log formatter. */ static jsonFormatter(data: LogEvent): string; /** * Currently active log level. */ get level(): string; set level(level: string); /** * Log `trace` message. */ trace(msg: string, context?: LogContext): void; /** * Log `warn` message. */ warn(msg: string, context?: LogContext): void; _log(level: string, msg: string, context?: LogContext): void; } /** * Captured log message class. */ declare class CapturedLogs extends Array<string> { _cb: () => void; _stopped: boolean; constructor(cb: () => void); /** * Stop capturing log messages. */ stop(): void; /** * Turn log messages into a string. */ toString(): string; } /** * Child logger class. */ export declare class ChildLogger { parent: Logger; context: LogContext; constructor(parent: Logger, context: LogContext); /** * Log `debug` message. */ debug(msg: string): void; /** * Log `error` message. */ error(msg: string): void; /** * Log `fatal` message. */ fatal(msg: string): void; /** * Log `info` message. */ info(msg: string): void; /** * Log `trace` message. */ trace(msg: string): void; /** * Log `warn` message. */ warn(msg: string): void; } export {};