/** * Logger * * Provides structured logging with levels, formatting, file rotation, * operation tracing, and performance timing. */ /** * Log levels in order of severity */ export type LogLevel = 'debug' | 'info' | 'warn' | 'error'; /** * Structured context data for log entries */ export interface LogContext { [key: string]: unknown; } /** * Serialized error structure for logging */ export interface SerializedError { name: string; message: string; code?: string; plgCode?: string; stack?: string[]; cause?: SerializedError; } /** * Log entry structure (enhanced) */ export interface LogEntry { timestamp: string; level: LogLevel; message: string; category?: string; duration?: number; operationId?: string; context?: LogContext; error?: SerializedError; } /** * Logger configuration options */ export interface LoggerOptions { level?: LogLevel; console?: boolean; stderr?: boolean; colorize?: boolean; filePath?: string; /** Path for human-readable log file (separate from JSONL) */ humanReadablePath?: string; maxFileSize?: number; maxFiles?: number; timestamps?: boolean; name?: string; /** Category filter patterns (e.g., ['sources:*', '-sources:github']) */ categoryFilter?: string[]; /** Per-category log levels */ categoryLevels?: Record; /** Duration threshold for warning (ms) */ warnThreshold?: number; /** Duration threshold for slow indicator (ms) */ slowThreshold?: number; /** Make log files read-only after writing */ readOnlyFiles?: boolean; } /** * Serialize an error for structured logging */ export declare function serializeError(error: Error): SerializedError; /** * Parse category filter patterns from environment or config */ export declare function parseCategoryFilter(patterns: string | string[]): string[]; /** * Check if a category matches the filter patterns */ export declare function categoryMatches(category: string, patterns: string[]): boolean; /** * Logger class with multiple outputs, rotation, and structured logging */ export declare class Logger { protected options: Required; protected operationId?: string; constructor(options?: LoggerOptions); /** * Check if a log level should be output */ private shouldLog; /** * Format a log entry for human-readable console output */ private formatForConsole; /** * Format context data for console output */ private formatContextForConsole; /** * Format a log entry as JSONL for file output */ private formatAsJsonl; /** * Rotate log files if needed * @param targetPath Optional specific file path to rotate (defaults to JSONL file) */ private rotateIfNeeded; /** * Get the effective file path (inherit from global logger if not set locally) */ private getEffectiveFilePath; /** * Get the effective human-readable file path (inherit from global logger if not set locally) */ private getEffectiveHumanReadablePath; /** * Get the effective log level (inherit from global logger if not set locally) */ private getEffectiveLevel; /** * Write a log entry */ private write; /** * Log a debug message */ debug(message: string, context?: LogContext): void; /** * Log an info message */ info(message: string, context?: LogContext): void; /** * Log a warning message */ warn(message: string, context?: LogContext): void; /** * Log an error message */ error(message: string, context?: LogContext): void; /** * Log an error with full serialization */ logError(error: Error, context?: LogContext): void; /** * Start timing an operation * Returns an end function that logs the duration */ time(label: string): () => void; /** * Log a message with duration */ logWithDuration(level: LogLevel, message: string, duration: number, context?: LogContext): void; /** * Start a traced operation * Returns an OperationLogger that includes the operation ID in all logs */ startOperation(name: string): OperationLogger; /** * Create a child logger with a specific name */ child(name: string): Logger; /** * Create a child logger with a specific operation ID (used internally) */ protected createChildWithOperationId(name: string, opId?: string): Logger; /** * Set the log level */ setLevel(level: LogLevel): void; /** * Get the current log level */ getLevel(): LogLevel; /** * Get the logger name/category */ getName(): string; } /** * Logger for traced operations with automatic timing and operation ID */ export declare class OperationLogger extends Logger { private readonly opId; private operationName; private startTime; constructor(options: LoggerOptions, operationName: string, operationId: string); /** * Get the operation ID */ getOperationId(): string; /** * End the operation and log completion */ end(result?: 'success' | 'failure', context?: LogContext): void; /** * Create a child logger that preserves the operation ID */ child(name: string): Logger; } /** * Get or create the global logger */ export declare function getLogger(): Logger; /** * Configure the global logger */ export declare function configureLogger(options: LoggerOptions): Logger; /** * Create a named logger (child of global). * * When called without options, returns a proxy that delegates to the current * global logger. This ensures module-scope loggers (created before configureLogger() * runs) pick up the configured file paths, levels, and filters. */ export declare function createLogger(name: string, options?: LoggerOptions): Logger; /** * Convenience exports for global logger */ export declare const log: { debug: (message: string, context?: LogContext) => void; info: (message: string, context?: LogContext) => void; warn: (message: string, context?: LogContext) => void; error: (message: string, context?: LogContext) => void; logError: (error: Error, context?: LogContext) => void; time: (label: string) => () => void; startOperation: (name: string) => OperationLogger; }; //# sourceMappingURL=logger.d.ts.map