UNPKG

@tobes31415/console-logger

Version:

Formats console logs while preserving stack trace info

54 lines (53 loc) 1.8 kB
import { Observable } from "@tobes31415/basic-observables"; /** * Log level matches the console log levels */ export declare enum LogLevel { debug = "debug", error = "error", info = "info", warn = "warn" } /** * The information broadcast to the observable when the logger is invoked */ export interface LogEvent { message: string; extras: any[]; namespace: string; time: Date; uptime: number; level: LogLevel; } /** * The sections of the log event controlled by the formatter */ export type LogEventFormatSections = keyof Omit<LogEvent, "extras">; /** * Use this inside your console.log( ) to add formatting as well as forking to any third party loggers you may be using * * console.log(...logger("This is a test")); // if you omit the level it is assumed to be a debug message * console.error(...logger.error("This is an error")); */ export interface Logger { (message: string, ...extras: any[]): any[]; debug(message: string, ...extras: any[]): any[]; error(message: string, ...extras: any[]): any[]; warn(message: string, ...extras: any[]): any[]; info(message: string, ...extras: any[]): any[]; config(newConfig: Partial<LoggerConfig>): void; } /** * */ export interface LoggerConfig { defaultLogLevel: LogLevel; logThreshold: LogLevel; include: (LogEventFormatSections | string)[]; style?: Partial<Record<LogEventFormatSections, string>>; format?: Partial<Record<LogEventFormatSections, string | ((value: any) => string)>>; delimiter: string; } export declare const onLogEvent: Observable<LogEvent>; export declare function customizeDefaultLogConfig(newConfig: Partial<LoggerConfig>): void; export declare function createLoggerFor(namespace: string, config?: Partial<LoggerConfig>): Logger;