import { LoggerConfig } from '../../types'; /** * Main logger class for the CertusAdiValt system with structured logging capabilities. * * Provides a comprehensive logging solution with multiple log levels, formatting options, * sensitive data redaction, performance timing, and child logger support. Supports both * JSON and pretty-printed formats for different environments. * * @class ValtLogger * * @example * ```typescript * // Create logger instance * const logger = new ValtLogger({ * level: LogLevel.INFO, * service: 'user-service', * environment: 'production', * version: '1.0.0', * redactFields: ['password', 'token'], * prettyPrint: false * }); * * // Basic logging * logger.info('User logged in', { userId: '123', method: 'oauth' }); * logger.error('Database connection failed', { host: 'db.example.com' }, error); * * // Performance timing * const result = logger.time('database-query', () => { * return database.query('SELECT * FROM users'); * }); * * // Child logger with shared context * const requestLogger = logger.child({ requestId: 'req_123', userId: 'user_456' }); * requestLogger.info('Processing request'); * ``` */ export declare class ValtLogger { private config; private jsonFormat; private prettyFormat; /** * Creates a new ValtLogger instance with the specified configuration. * * @param {LoggerConfig} config - Logger configuration options * * @example * ```typescript * // Production configuration * const prodLogger = new ValtLogger({ * level: LogLevel.INFO, * service: 'api-gateway', * environment: 'production', * version: '2.1.0', * redactFields: ['password', 'authorization', 'apiKey'], * prettyPrint: false * }); * * // Development configuration * const devLogger = new ValtLogger({ * level: LogLevel.DEBUG, * service: 'api-gateway', * environment: 'development', * prettyPrint: true * }); * ``` */ constructor(config: LoggerConfig); /** * Checks if a log level should be logged based on configured minimum level. * * @private * @param {LogLevel} level - The log level to check * @returns {boolean} True if the level should be logged */ private shouldLog; /** * Creates a structured log entry with proper formatting and redaction. * * @private * @param {LogLevel} level - The log level * @param {string} message - The log message * @param {Record} [context] - Optional context data * @param {Error} [error] - Optional error object * @returns {LogEntry} Structured log entry */ private createLogEntry; /** * Redacts sensitive data from context objects based on configuration. * * @private * @param {Record} data - The data to redact * @returns {Record} Redacted data */ private redactSensitiveData; /** * Writes a log entry to the appropriate output stream with formatting. * * @private * @param {LogEntry} entry - The log entry to write */ private writeLog; /** * Gets the appropriate console method for a log level. * * @private * @param {LogLevel} level - The log level * @returns {(...args: any[]) => void} Console method function */ private getConsoleMethod; /** * Logs an error message with optional context and error object. * * @param {string} message - The error message * @param {Record} [context] - Optional context data * @param {Error} [error] - Optional error object * * @example * ```typescript * try { * await someOperation(); * } catch (error) { * logger.error('Operation failed', { operation: 'user-create' }, error); * } * * logger.error('Invalid configuration', { configKey: 'database.url' }); * ``` */ error(message: string, context?: Record, error?: Error): void; /** * Logs a warning message with optional context and error object. * * @param {string} message - The warning message * @param {Record} [context] - Optional context data * @param {Error} [error] - Optional error object * * @example * ```typescript * logger.warn('Deprecated API called', { endpoint: '/v1/users', alternative: '/v2/users' }); * logger.warn('High memory usage', { usage: '85%', threshold: '80%' }); * ``` */ warn(message: string, context?: Record, error?: Error): void; /** * Logs an informational message with optional context. * * @param {string} message - The info message * @param {Record} [context] - Optional context data * * @example * ```typescript * logger.info('User registered', { userId: '123', method: 'email' }); * logger.info('Server started', { port: 3000, environment: 'production' }); * ``` */ info(message: string, context?: Record): void; /** * Logs a debug message with optional context. * * @param {string} message - The debug message * @param {Record} [context] - Optional context data * * @example * ```typescript * logger.debug('Database query executed', { query: 'SELECT * FROM users', duration: 45 }); * logger.debug('Cache hit', { key: 'user:123', ttl: 300 }); * ``` */ debug(message: string, context?: Record): void; /** * Logs a trace message with optional context. * * @param {string} message - The trace message * @param {Record} [context] - Optional context data * * @example * ```typescript * logger.trace('Function called', { args: ['param1', 'param2'], caller: 'userService' }); * logger.trace('State updated', { previous: 'pending', current: 'completed' }); * ``` */ trace(message: string, context?: Record): void; /** * Times the execution of a function and logs the duration. * * @template T - The return type of the function * @param {string} operation - The operation name for logging * @param {() => T} fn - The function to time * @param {Record} [context] - Optional context data * @returns {T} The result of the function * * @example * ```typescript * // Sync function * const result = logger.time('process-data', () => { * return processLargeDataset(data); * }, { records: data.length }); * * // Async function * const user = await logger.time('fetch-user', async () => { * return await userRepository.findById(userId); * }, { userId }); * * // With error handling * try { * const result = logger.time('risky-operation', riskyFunction, { param: value }); * } catch (error) { * // Duration is logged even if operation fails * } * ``` */ time(operation: string, fn: () => T, context?: Record): T; /** * Logs the duration of an operation. * * @private * @param {string} operation - The operation name * @param {number} duration - The duration in milliseconds * @param {Record} [context] - Optional context data */ private logDuration; /** * Creates a child logger with inherited context. * * @param {Record} context - Context to include in all child logs * @returns {ValtLogger} Child logger instance * * @example * ```typescript * // Create child logger for request context * const requestLogger = logger.child({ * requestId: 'req_123', * userId: 'user_456', * sessionId: 'sess_789' * }); * * requestLogger.info('Processing request'); // Includes request context * requestLogger.debug('Database query', { table: 'users' }); // Merges contexts * * // Create child logger for module context * const authLogger = logger.child({ module: 'authentication' }); * authLogger.info('User authenticated', { method: 'jwt' }); * ``` */ child(context: Record): ValtLogger; }