| 23 | const RESET = '\x1b[0m'; |
| 24 | |
| 25 | function log(level: LogLevel, message: string, extra?: any): void { |
| 26 | const timestamp = new Date().toISOString(); |
| 27 | const color = levelColors[level] ?? ''; |
| 28 | const prefix = `[${timestamp}] [PID: ${process.pid}] ${GREEN}[NODE-CRON]${GREEN} ${color}[${level}]${RESET}`; |
| 29 | const output = `${prefix} ${message}`; |
| 30 | |
| 31 | switch (level) { |
| 32 | case 'ERROR': |
| 33 | console.error(output, extra ?? ''); |
| 34 | break; |
| 35 | case 'DEBUG': |
| 36 | console.debug(output, extra ?? ''); |
| 37 | break; |
| 38 | case 'WARN': |
| 39 | console.warn(output); |
| 40 | break; |
| 41 | case 'INFO': |
| 42 | default: |
| 43 | console.info(output); |
| 44 | break; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * The built-in console logger. Used by default unless replaced via `setLogger`. |