UNPKG

@clipwhisperer/common

Version:

ClipWhisperer Common - Shared library providing core utilities, database schemas, authentication, bucket management, and common functionality across all ClipWhisperer microservices

107 lines (106 loc) 3.65 kB
export type LogLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace'; export type LogContext = Record<string, any>; export interface LogEntry { timestamp: string; level: LogLevel; message: string; context?: LogContext; correlationId?: string; service?: string; component?: string; error?: { name: string; message: string; stack?: string; }; metadata?: { pid: number; hostname: string; version: string; }; } export interface LogTransport { name: string; write(entry: LogEntry): Promise<void>; flush?(): Promise<void>; close?(): Promise<void>; } /** * Console transport for logging to stdout/stderr */ export declare class ConsoleTransport implements LogTransport { readonly name = "console"; private readonly colors; constructor(colors?: boolean); write(entry: LogEntry): Promise<void>; private formatEntry; private colorizeLevel; } /** * File transport for logging to files with rotation */ export declare class FileTransport implements LogTransport { readonly name = "file"; private writeStream; private readonly logPath; private readonly maxFileSize; private readonly maxFiles; private currentFileSize; constructor(logPath: string, maxFileSize?: number, // 10MB maxFiles?: number); write(entry: LogEntry): Promise<void>; flush(): Promise<void>; close(): Promise<void>; private createWriteStream; private rotateLogFile; } /** * Enterprise-grade structured logger with multiple transports and correlation tracking */ export declare class Logger { private static instance; private transports; private logLevel; private correlationId; private service; private component; private readonly logLevels; private constructor(); static getInstance(): Logger; private initializeTransports; setCorrelationId(correlationId: string): void; setService(service: string): void; setComponent(component: string): void; clearContext(): void; child(context: { service?: string; component?: string; correlationId?: string; }): Logger; error(message: string, context?: LogContext, error?: Error): void; warn(message: string, context?: LogContext): void; info(message: string, context?: LogContext): void; debug(message: string, context?: LogContext): void; trace(message: string, context?: LogContext): void; log(level: LogLevel, message: string, context?: LogContext, error?: Error): void; private shouldLog; private writeToTransports; addTransport(transport: LogTransport): void; removeTransport(name: string): boolean; getTransports(): LogTransport[]; flush(): Promise<void>; close(): Promise<void>; performance<T>(operation: string, fn: () => Promise<T>): Promise<T>; performanceSync<T>(operation: string, fn: () => Promise<T>): Promise<T>; metric(name: string, value: number, tags?: Record<string, string>): void; counter(name: string, increment?: number, tags?: Record<string, string>): void; gauge(name: string, value: number, tags?: Record<string, string>): void; histogram(name: string, value: number, tags?: Record<string, string>): void; audit(action: string, resource: string, context?: LogContext): void; security(event: string, details: LogContext): void; health(service: string, status: 'healthy' | 'unhealthy' | 'degraded', details?: LogContext): void; static generateCorrelationId(): string; generateCorrelationId(): string; } declare const _default: Logger; export default _default;