/** * @db4/core - Structured Logging * * A production-grade structured logging module with: * - Log levels: debug, info, warn, error, silent * - Structured JSON output with ISO8601 timestamps * - Context injection and child loggers * - Lazy evaluation for performance * - Automatic redaction of sensitive fields * - Timer support for operation timing * - Multiple outputs with per-output level filtering * - Batching support for high-throughput scenarios * * @packageDocumentation */ /** * Log levels in order of severity (debug < info < warn < error < silent). */ export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent'; /** * Source location information for log entries. */ export interface SourceLocation { file: string; line: number; column?: number; function?: string; } /** * Serialized error information. */ export interface SerializedError { name: string; message: string; stack?: string; code?: string; details?: Record; cause?: SerializedError; [key: string]: unknown; } /** * A single log entry. */ export interface LogEntry { /** ISO8601 timestamp */ timestamp: string; /** Log level */ level: LogLevel; /** Log message */ message: string; /** Sequence number for ordering */ sequence: number; /** Correlation ID for request tracing */ correlationId?: string; /** Additional context data */ context?: Record; /** Source location (if enabled) */ source?: SourceLocation; /** Error information (if logging an error) */ error?: SerializedError; } /** * Output interface for log entries. */ export interface LogOutput { write(entry: LogEntry): void; } /** * Redaction pattern for key-based redaction. */ export interface RedactionPattern { /** Regex pattern to match against field keys */ key: RegExp; /** Replacement string (default: '[REDACTED]') */ replacement?: string; } /** * Value-based redaction pattern. */ export interface ValueRedactionPattern { /** Regex pattern to match against field values */ pattern: RegExp; /** Replacement string */ replacement: string; } /** * Configuration for redaction behavior. */ export interface RedactionConfig { /** Enable/disable redaction (default: true) */ enabled?: boolean; /** Key-based redaction patterns (merged with defaults) */ patterns?: RedactionPattern[]; /** Value-based redaction patterns */ valuePatterns?: ValueRedactionPattern[]; /** Use default patterns in addition to custom ones (default: true) */ useDefaults?: boolean; } /** * Output configuration with level filtering. */ export interface OutputConfig { output: LogOutput; level?: LogLevel; } /** * Sampling configuration per log level. */ export interface SamplingConfig { debug?: number; info?: number; warn?: number; error?: number; } /** * Batching configuration. */ export interface BatchConfig { enabled: boolean; /** Number of entries to buffer before flushing */ size: number; /** Interval in ms to flush even if batch not full */ interval: number; } /** * Logger configuration options. */ export interface LoggerConfig { /** Minimum log level (default: 'info') */ level?: LogLevel; /** Single output destination */ output?: LogOutput; /** Multiple output destinations (mutually exclusive with output) */ outputs?: (LogOutput | OutputConfig)[]; /** Base context to include in all entries */ context?: Record; /** Redaction configuration */ redaction?: RedactionConfig; /** Include source location in entries */ includeSource?: boolean; /** Message format: 'template' (default) or 'printf' */ format?: 'template' | 'printf'; /** Sampling rates per level (0-1) */ sampling?: SamplingConfig; /** Batching configuration */ batch?: BatchConfig; } /** * Timer for measuring operation duration. */ export interface LogTimer { /** End the timer and log the result */ end(message: string, options?: { level?: LogLevel; context?: Record; }): void; } /** * Logger interface. */ export interface Logger { /** Log a debug message */ debug = Record>(message: string | (() => string), context?: T | (() => T), ...args: unknown[]): void; /** Log an info message */ info = Record>(message: string | (() => string), context?: T | (() => T), ...args: unknown[]): void; /** Log a warning message */ warn = Record>(message: string | (() => string), context?: T | (() => T), ...args: unknown[]): void; /** Log an error message */ error = Record>(message: string | (() => string), context?: T | (() => T), ...args: unknown[]): void; /** Get current log level */ getLevel(): LogLevel; /** Set log level */ setLevel(level: LogLevel): void; /** Check if a level is enabled */ isLevelEnabled(level: LogLevel): boolean; /** Add context to all future log entries */ addContext(context: Record): void; /** Create a child logger with additional context */ child(context: Record): Logger; /** Create a logger with a correlation ID */ withCorrelationId(correlationId: string): Logger; /** Start a timer for measuring operation duration */ startTimer(name: string): LogTimer; /** Flush any batched log entries */ flush(): Promise; } /** * Default patterns for redacting sensitive fields. */ export declare const DEFAULT_REDACTION_PATTERNS: RedactionPattern[]; /** * Create a new logger instance. */ export declare function createLogger(config?: LoggerConfig): Logger; /** * Create a silent logger that discards all output. * Useful for testing. */ export declare function createSilentLogger(): Logger; /** * Create a console logger with default configuration. */ export declare function createConsoleLogger(level?: LogLevel): Logger; //# sourceMappingURL=logging.d.ts.map