UNPKG

@200systems/mf-logger

Version:

Structured logging with multiple outputs and performance timing for TypeScript applications

76 lines 2.23 kB
export type LogLevel = 'debug' | 'info' | 'warn' | 'error'; export interface LogEntry { timestamp: string; level: LogLevel; message: string; context?: string; metadata?: Record<string, any>; error?: { name: string; message: string; stack?: string; code?: string | number; }; request?: { id?: string; method?: string; url?: string; userAgent?: string; ip?: string; }; performance?: { duration?: number; memory?: NodeJS.MemoryUsage; }; } export interface LoggerConfig { level?: LogLevel; format?: 'json' | 'pretty'; context?: string; includeTimestamp?: boolean; includeStack?: boolean; metadata?: Record<string, any>; outputs?: LogOutput[]; } export interface LogOutput { type: 'console' | 'file' | 'custom' | 'remote'; options?: ConsoleOutputOptions | FileOutputOptions | CustomOutputOptions | RemoteOutputOptions; } export interface ConsoleOutputOptions { enhanced?: boolean; } export interface FileOutputOptions { filePath: string; maxSize?: number; maxFiles?: number; } export interface CustomOutputOptions { customHandler: (entry: LogEntry) => void | Promise<void>; } export interface RemoteOutputOptions { endpoint: string; batchSize?: number; flushInterval?: number; headers?: Record<string, string>; } export interface Logger { debug(message: string, metadata?: Record<string, any>): void; info(message: string, metadata?: Record<string, any>): void; warn(message: string, metadata?: Record<string, any>): void; error(message: string, error?: Error, metadata?: Record<string, any>): void; child(context: string, metadata?: Record<string, any>): Logger; addMetadata(key: string, value: any): void; removeMetadata(key: string): void; clearMetadata(): void; startTimer(name: string): () => void; retrieveStoredLogs?(): Array<{ timestamp: string; content: string; }> | null; clearStoredLogs?(): void; } export interface LogFormatter { formatJson(entry: LogEntry): string; formatPretty(entry: LogEntry): string; } //# sourceMappingURL=types.d.ts.map