(slug: string)
| 24 | * @returns Pino logger instance (or no-op logger on failure) |
| 25 | */ |
| 26 | export function initLogger(slug: string): Logger { |
| 27 | const cached = loggerCache.get(slug); |
| 28 | |
| 29 | if (cached) { |
| 30 | return cached.logger; |
| 31 | } |
| 32 | |
| 33 | try { |
| 34 | const logFilePath = `${LOG_DIR}/${slug}.log`; |
| 35 | |
| 36 | const config: LoggerConfig = { |
| 37 | slug, |
| 38 | logDir: LOG_DIR, |
| 39 | logFilePath, |
| 40 | }; |
| 41 | |
| 42 | const logger = createLogger(config); |
| 43 | |
| 44 | loggerCache.set(slug, { logger, config }); |
| 45 | |
| 46 | return logger; |
| 47 | } catch (error) { |
| 48 | // Log initialization failed - return a no-op logger to prevent CLI crashes |
| 49 | // The CLI will continue to work, but logging will be silently disabled |
| 50 | return createNoOpLogger(); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Create a logger with automatic log rotation. |
no test coverage detected