/** * Logging Middleware and Utilities * * Provides comprehensive logging capabilities for API requests, responses, and errors. * Supports multiple log levels and formats for development and production use. * * Compliance: * - ISO/IEC 25010:2023 Maintainability.Analyzability * - OWASP Security Logging and Monitoring */ import type { Elysia } from "elysia"; /** * Log levels in order of severity */ export declare enum LogLevel { DEBUG = 0, INFO = 1, WARN = 2, ERROR = 3, NONE = 4 } /** * Logging Configuration Options */ export interface LoggingOptions { /** Minimum log level to output (default: INFO) */ level?: LogLevel; /** Enable colorized output (default: true) */ colors?: boolean; /** Include timestamp in logs (default: true) */ timestamp?: boolean; /** Log request method and path (default: true) */ logRequests?: boolean; /** Log response status and time (default: true) */ logResponses?: boolean; /** Log request body (default: false, security risk) */ logRequestBody?: boolean; /** Log response body (default: false, may contain sensitive data) */ logResponseBody?: boolean; /** Custom log formatter function */ formatter?: (log: LogEntry) => string; /** Custom log writer function (default: console.log/error) */ writer?: (message: string, level: LogLevel) => void; } /** * Log Entry Structure */ export interface LogEntry { level: LogLevel; message: string; timestamp: Date; method?: string; path?: string; statusCode?: number; duration?: number; ip?: string; userAgent?: string; requestBody?: any; responseBody?: any; error?: Error; } /** * Logger class for structured logging */ export declare class Logger { private options; constructor(options?: LoggingOptions); /** * Default log formatter */ private defaultFormatter; /** * Default log writer */ private defaultWriter; /** * Get color for log level */ private getLevelColor; /** * Get color for HTTP status code */ private getStatusColor; /** * Log a message */ log(entry: Partial): void; /** * Log debug message */ debug(message: string, meta?: Partial): void; /** * Log info message */ info(message: string, meta?: Partial): void; /** * Log warning message */ warn(message: string, meta?: Partial): void; /** * Log error message */ error(message: string, error?: Error, meta?: Partial): void; } /** * Get the global logger instance */ export declare function getLogger(): Logger; /** * Configure the global logger */ export declare function configureLogger(options: LoggingOptions): void; /** * Configures logging middleware for the Elysia application * * This middleware logs all incoming requests and outgoing responses, providing * valuable information for debugging, monitoring, and auditing. * * Features: * - Request logging (method, path, IP, user agent) * - Response logging (status code, duration) * - Configurable log levels * - Colorized output for better readability * - Custom formatters and writers * - Request/response body logging (opt-in) * * Security Considerations: * - Request/response body logging is disabled by default (may contain sensitive data) * - Sanitize logs to prevent information leakage * - Consider log retention policies * - Protect log files from unauthorized access * * Compliance: * - ISO/IEC 25010:2023 Maintainability requirements * - OWASP Security Logging and Monitoring * - GDPR compliance (be careful with PII in logs) * * @param app - The Elysia application instance to configure * @param options - Logging configuration options * * @returns {void} * * @example * ```typescript * import { Elysia } from 'elysia'; * import { setupLogging, LogLevel } from './middleware/logging.middleware'; * * const app = new Elysia(); * * // Default logging * setupLogging(app); * * // Custom configuration * setupLogging(app, { * level: LogLevel.DEBUG, * colors: true, * logRequestBody: process.env.NODE_ENV === 'development', * logResponseBody: false * }); * * // Production logging with external service * setupLogging(app, { * level: LogLevel.WARN, * writer: (message, level) => { * // Send to logging service (DataDog, Loggly, etc.) * loggingService.log(level, message); * } * }); * ``` */ export declare function setupLogging(app: Elysia, options?: LoggingOptions): void; //# sourceMappingURL=logging.middleware.d.ts.map