| 1 | const config = require('./config'); |
| 2 | |
| 3 | const LEVELS = { debug: 10, info: 20, warn: 30, error: 40 }; |
| 4 | |
| 5 | function threshold() { |
| 6 | try { return LEVELS[config.get('log.level')] || LEVELS.info; } |
| 7 | catch { return LEVELS.info; } |
| 8 | } |
| 9 | |
| 10 | function ts() { return new Date().toISOString(); } |
| 11 | |
| 12 | function debug(...a) { if (LEVELS.debug >= threshold()) console.log(ts(), 'debug', ...a); } |
| 13 | function info(...a) { if (LEVELS.info >= threshold()) console.log(ts(), 'info', ...a); } |
| 14 | function warn(...a) { if (LEVELS.warn >= threshold()) console.warn(ts(), 'warn', ...a); } |
| 15 | function error(...a) { if (LEVELS.error >= threshold()) console.error(ts(), 'error', ...a); } |
| 16 | |
| 17 | module.exports = { debug, info, warn, error }; |
| 18 | |