/** * Block Logger Module * * Provides structured logging for block operations in BrightChain. * Supports configurable log levels and JSON-formatted output. * * @module logging/blockLogger * * @example * ```typescript * import { BlockLogger, LogLevel } from 'brightchain-lib'; * * const logger = new BlockLogger(); * logger.setLevel(LogLevel.DEBUG); * * logger.info('encrypt', { blockId: '0x123...', blockType: 'EncryptedBlock' }); * logger.error('decrypt', new Error('Decryption failed'), { blockId: '0x456...' }); * ``` * * @see Requirements 8.1, 8.2, 8.3, 8.4, 8.5, 8.6 */ /** * Log levels for block operations. * Ordered from most verbose (DEBUG) to least verbose (ERROR). */ export declare enum LogLevel { DEBUG = "debug", INFO = "info", WARN = "warn", ERROR = "error" } /** * Structured log entry for block operations. * All entries are JSON-serializable for machine parsing. * * @see Requirement 8.4 - Structured JSON format */ export interface BlockLogEntry { /** ISO 8601 timestamp of the log entry */ timestamp: string; /** Log level (debug, info, warn, error) */ level: LogLevel; /** Operation being performed (e.g., 'encrypt', 'decrypt', 'validate') */ operation: string; /** Block ID (hex-encoded checksum) - not sensitive */ blockId?: string; /** Block type name */ blockType?: string; /** Additional metadata (never contains sensitive data) */ metadata?: Record; /** Error information if applicable */ error?: { /** Error class name */ type: string; /** Error message (sanitized) */ message: string; }; } /** * Interface for block logging operations. * Implementations must ensure sensitive data is never logged. * * @see Requirement 8.6 - No sensitive data in logs */ export interface IBlockLogger { /** * Log a debug-level message. * @param operation - The operation being performed * @param metadata - Optional metadata (must not contain sensitive data) */ debug(operation: string, metadata?: Record): void; /** * Log an info-level message. * @param operation - The operation being performed * @param metadata - Optional metadata (must not contain sensitive data) */ info(operation: string, metadata?: Record): void; /** * Log a warning-level message. * @param operation - The operation being performed * @param metadata - Optional metadata (must not contain sensitive data) */ warn(operation: string, metadata?: Record): void; /** * Log an error-level message. * @param operation - The operation being performed * @param error - The error that occurred * @param metadata - Optional metadata (must not contain sensitive data) */ error(operation: string, error: Error, metadata?: Record): void; /** * Set the minimum log level. * Messages below this level will be suppressed. * @param level - The minimum log level to emit */ setLevel(level: LogLevel): void; /** * Get the current log level. * @returns The current minimum log level */ getLevel(): LogLevel; } /** * BlockLogger implementation with configurable output and log levels. * * Features: * - Structured JSON log entries * - Configurable log levels with filtering * - Automatic sensitive data sanitization * - Configurable output destination * * @see Requirements 8.4, 8.5, 8.6 * * @example * ```typescript * // Create logger with custom output * const entries: BlockLogEntry[] = []; * const logger = new BlockLogger((entry) => entries.push(entry)); * * // Set log level * logger.setLevel(LogLevel.WARN); * * // These will be suppressed * logger.debug('operation', { detail: 'value' }); * logger.info('operation', { detail: 'value' }); * * // These will be logged * logger.warn('operation', { detail: 'value' }); * logger.error('operation', new Error('Failed'), { detail: 'value' }); * ``` */ export declare class BlockLogger implements IBlockLogger { private level; private output; private _silent; /** * Create a new BlockLogger. * @param output - Optional custom output function. Defaults to console output. */ constructor(output?: (entry: BlockLogEntry) => void); /** * Enable or disable all output (useful for tests) */ set silent(value: boolean); get silent(): boolean; /** * Set the minimum log level. * @param level - The minimum log level to emit */ setLevel(level: LogLevel): void; /** * Get the current log level. * @returns The current minimum log level */ getLevel(): LogLevel; /** * Check if a log level should be emitted based on current level setting. * @param level - The level to check * @returns true if the level should be emitted */ private shouldLog; /** * Create a log entry with common fields. * @param level - The log level * @param operation - The operation being performed * @param metadata - Optional metadata * @returns The log entry */ private createEntry; /** * Emit a log entry if the level is enabled. * @param entry - The log entry to emit */ private emit; /** * Log a debug-level message. * @param operation - The operation being performed * @param metadata - Optional metadata (must not contain sensitive data) */ debug(operation: string, metadata?: Record): void; /** * Log an info-level message. * @param operation - The operation being performed * @param metadata - Optional metadata (must not contain sensitive data) */ info(operation: string, metadata?: Record): void; /** * Log a warning-level message. * @param operation - The operation being performed * @param metadata - Optional metadata (must not contain sensitive data) */ warn(operation: string, metadata?: Record): void; /** * Log an error-level message. * @param operation - The operation being performed * @param error - The error that occurred * @param metadata - Optional metadata (must not contain sensitive data) */ error(operation: string, error: Error, metadata?: Record): void; } /** * Global block logger instance. * Can be used directly or replaced with a custom logger. */ export declare const blockLogger: BlockLogger; /** * Log a validation failure with error type and metadata. * This is a convenience function for block validation operations. * * @param blockId - The block ID (hex-encoded checksum) * @param blockType - The block type name * @param error - The validation error * @param metadata - Optional additional metadata * * @see Requirement 8.3 - Validation failure logging */ export declare function logValidationFailure(blockId: string | undefined, blockType: string | undefined, error: Error, metadata?: Record): void; //# sourceMappingURL=blockLogger.d.ts.map