* Create a logger with automatic log rotation.
(config: LoggerConfig)
| 55 | * Create a logger with automatic log rotation. |
| 56 | */ |
| 57 | function createLogger(config: LoggerConfig): Logger { |
| 58 | const logFileName = basename(config.logFilePath); |
| 59 | |
| 60 | // Create rotating file stream with smart defaults |
| 61 | const stream = createStream(logFileName, { |
| 62 | size: LOG_ROTATION_MAX_SIZE, // Rotate at 10MB |
| 63 | interval: LOG_ROTATION_INTERVAL, // Daily rotation |
| 64 | maxFiles: LOG_ROTATION_MAX_FILES, // Keep 10 files |
| 65 | compress: LOG_ROTATION_COMPRESS, // Gzip old files |
| 66 | path: config.logDir, // Directory for logs |
| 67 | }); |
| 68 | |
| 69 | // Handle runtime errors on the stream to prevent crashes |
| 70 | stream.on("error", (err) => { |
| 71 | // Log to stderr so errors are visible but don't crash the CLI |
| 72 | console.error(`[Logger error]: ${err.message}`); |
| 73 | }); |
| 74 | |
| 75 | const logger = pino( |
| 76 | { |
| 77 | level: DEFAULT_LOG_LEVEL, |
| 78 | redact: { |
| 79 | paths: [...DEFAULT_REDACT_PATHS], |
| 80 | censor: "[REDACTED]", |
| 81 | }, |
| 82 | }, |
| 83 | stream, |
| 84 | ); |
| 85 | |
| 86 | return logger; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Create a no-op logger that discards all log messages. |