UNPKG

logs-interceptor

Version:

High-performance, production-ready log interceptor for Node.js applications with Loki integration

136 lines 4.03 kB
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'fatal'; export interface LogEntry { timestamp: string; level: LogLevel; message: string; context?: Record<string, unknown>; traceId?: string; spanId?: string; labels?: Record<string, string>; } export interface LokiStream { stream: Record<string, string>; values: [string, string][]; } export interface LokiPayload { streams: LokiStream[]; } export interface TransportOptions { url: string; tenantId: string; authToken?: string; timeout?: number; maxRetries?: number; retryDelay?: number; compression?: boolean; } export interface ResolvedTransportOptions { url: string; tenantId: string; authToken: string; timeout: number; maxRetries: number; retryDelay: number; compression: boolean; } export interface BufferOptions { maxSize?: number; flushInterval?: number; maxAge?: number; autoFlush?: boolean; } export interface ResolvedBufferOptions { maxSize: number; flushInterval: number; maxAge: number; autoFlush: boolean; } export interface FilterOptions { levels?: LogLevel[]; patterns?: RegExp[]; samplingRate?: number; maxMessageLength?: number; } export interface ResolvedFilterOptions { levels: LogLevel[]; patterns: RegExp[]; samplingRate: number; maxMessageLength: number; } export interface LogsInterceptorConfig { transport: TransportOptions; appName: string; version?: string; environment?: string; labels?: Record<string, string>; dynamicLabels?: Record<string, () => string | number>; buffer?: BufferOptions; filter?: FilterOptions; enableMetrics?: boolean; enableHealthCheck?: boolean; interceptConsole?: boolean; preserveOriginalConsole?: boolean; debug?: boolean; silentErrors?: boolean; } export interface ResolvedLogsInterceptorConfig { transport: ResolvedTransportOptions; appName: string; version: string; environment: string; labels: Record<string, string>; dynamicLabels: Record<string, () => string | number>; buffer: ResolvedBufferOptions; filter: ResolvedFilterOptions; enableMetrics: boolean; enableHealthCheck: boolean; interceptConsole: boolean; preserveOriginalConsole: boolean; debug: boolean; silentErrors: boolean; } export interface LoggerMetrics { logsProcessed: number; logsDropped: number; flushCount: number; errorCount: number; bufferSize: number; avgFlushTime: number; lastFlushTime: number; } export interface HealthStatus { healthy: boolean; lastSuccessfulFlush: number; consecutiveErrors: number; bufferUtilization: number; uptime: number; } export interface LoggerInstance { log(level: LogLevel, message: string, context?: Record<string, unknown>): void; debug(message: string, context?: Record<string, unknown>): void; info(message: string, context?: Record<string, unknown>): void; warn(message: string, context?: Record<string, unknown>): void; error(message: string, context?: Record<string, unknown>): void; fatal(message: string, context?: Record<string, unknown>): void; trackEvent(eventName: string, properties?: Record<string, unknown>): void; flush(): Promise<void>; getMetrics(): LoggerMetrics; getHealth(): HealthStatus; destroy(): Promise<void>; } export interface EnvironmentConfig { LOGS_INTERCEPTOR_URL?: string; LOGS_INTERCEPTOR_TENANT_ID?: string; LOGS_INTERCEPTOR_AUTH_TOKEN?: string; LOGS_INTERCEPTOR_APP_NAME?: string; LOGS_INTERCEPTOR_ENVIRONMENT?: string; LOGS_INTERCEPTOR_VERSION?: string; LOGS_INTERCEPTOR_LABELS?: string; LOGS_INTERCEPTOR_BUFFER_SIZE?: string; LOGS_INTERCEPTOR_FLUSH_INTERVAL?: string; LOGS_INTERCEPTOR_LOG_LEVEL?: string; LOGS_INTERCEPTOR_ENABLED?: string; LOGS_INTERCEPTOR_DEBUG?: string; LOGS_INTERCEPTOR_SAMPLING_RATE?: string; } //# sourceMappingURL=types.d.ts.map