UNPKG

@wgtechlabs/log-engine

Version:

A lightweight, security-first logging utility with automatic data redaction for Node.js applications - the first logging library with built-in PII protection.

171 lines 7.37 kB
/** * Core Logger class that handles log message output with configurable levels * Supports DEBUG, INFO, WARN, ERROR, and LOG levels with intelligent filtering * LOG level always outputs regardless of configuration * Uses colorized console output with timestamps for better readability * Includes automatic data redaction for sensitive information */ import { LoggerConfig, LogData } from '../types'; /** * Logger class responsible for managing log output and configuration * Provides mode-based filtering and formatted console output */ export declare class Logger { private configManager; private cachedConfig; /** * Logger constructor - sets up environment-based auto-configuration */ constructor(); /** * Get cached configuration or refresh cache if needed * This avoids repeated getConfig() calls for better performance */ private getCachedConfig; /** * Invalidate the configuration cache when configuration changes */ private invalidateConfigCache; /** * Helper method to format log messages with cached configuration * Reduces code duplication across all log methods * @param level - The log level to format for * @param message - The message content to format * @param data - Optional data object to include in the log output * @returns Formatted string with appropriate configuration applied */ private formatMessage; /** * Built-in output handlers for common use cases */ private getBuiltInHandler; /** * Process a single output target with error handling * @param output - Single output target to process * @param level - Log level * @param rawMessage - Original unformatted message * @param formattedMessage - Formatted message for console-based outputs * @param data - Optional data * @param isEnhanced - Whether this is an enhanced output (supports configured handler objects) */ private processSingleOutput; /** * Process multiple output targets * @param outputs - Array of output targets to process * @param level - Log level * @param rawMessage - Original unformatted message * @param formattedMessage - Formatted message for console-based outputs * @param data - Optional data */ private processOutputs; /** * Process enhanced output targets * @param enhancedOutputs - Array of enhanced output targets to process * @param level - Log level * @param rawMessage - Original unformatted message * @param formattedMessage - Formatted message for console-based outputs * @param data - Optional data */ private processEnhancedOutputs; /** * Updates logger configuration with new settings * Also updates redaction configuration based on environment * @param config - Partial configuration object to apply */ configure(config: Partial<LoggerConfig>): void; /** * Get current logger configuration * @returns Current logger configuration */ getConfig(): LoggerConfig; /** * Determines if a message should be logged based on current log mode * @param level - The log level of the message to check * @returns true if message should be logged, false otherwise */ private shouldLog; /** * Writes log output using configured output handler or default console methods * Supports single output handler, multiple outputs, and enhanced outputs * Priority: outputs > enhancedOutputs > outputHandler > default console * @param level - The log level as a string * @param rawMessage - The original unformatted message * @param formattedMessage - The pre-formatted message to output * @param data - Optional data object that was logged * @param isError - Whether this is an error level message (for console.error) * @param isWarn - Whether this is a warning level message (for console.warn) */ private writeToOutput; /** * Log a debug message with DEBUG level formatting * Uses console.log for output with purple/magenta coloring * Automatically redacts sensitive data when provided * @param message - The debug message to log * @param data - Optional data object to log (will be redacted) */ debug(message: string, data?: LogData): void; /** * Log an informational message with INFO level formatting * Uses console.log for output with blue coloring * Automatically redacts sensitive data when provided * @param message - The info message to log * @param data - Optional data object to log (will be redacted) */ info(message: string, data?: LogData): void; /** * Log a warning message with WARN level formatting * Uses console.warn for output with yellow coloring * Automatically redacts sensitive data when provided * @param message - The warning message to log * @param data - Optional data object to log (will be redacted) */ warn(message: string, data?: LogData): void; /** * Log an error message with ERROR level formatting * Uses console.error for output with red coloring * Automatically redacts sensitive data when provided * @param message - The error message to log * @param data - Optional data object to log (will be redacted) */ error(message: string, data?: LogData): void; /** * Log a message with LOG level formatting (always outputs unless mode is OFF) * Uses console.log for output with green coloring * LOG level bypasses normal filtering and always outputs (except when OFF is set) * Automatically redacts sensitive data when provided * @param message - The log message to output * @param data - Optional data object to log (will be redacted) */ log(message: string, data?: LogData): void; /** * Log a debug message without data redaction * @param message - The debug message to log * @param data - Optional data object to log (no redaction applied) */ debugRaw(message: string, data?: LogData): void; /** * Log an info message without data redaction * @param message - The info message to log * @param data - Optional data object to log (no redaction applied) */ infoRaw(message: string, data?: LogData): void; /** * Log a warning message without data redaction * @param message - The warning message to log * @param data - Optional data object to log (no redaction applied) */ warnRaw(message: string, data?: LogData): void; /** * Log an error message without data redaction * @param message - The error message to log * @param data - Optional data object to log (no redaction applied) */ errorRaw(message: string, data?: LogData): void; /** * Log a message without data redaction (always outputs unless mode is OFF) * @param message - The log message to output * @param data - Optional data object to log (no redaction applied) */ logRaw(message: string, data?: LogData): void; } //# sourceMappingURL=core.d.ts.map