lib/log.js - git - Webernet Explorer _X
git 🏠 Home 👤 Sign up Self hosted git, retro shell
★ otgit, code hosting from the year 2000 ★
📄 octuna / lib / log.js
18 lines · 0.7 KB · Raw
1const config = require('./config');
2 
3const LEVELS = { debug: 10, info: 20, warn: 30, error: 40 };
4 
5function threshold() {
6 try { return LEVELS[config.get('log.level')] || LEVELS.info; }
7 catch { return LEVELS.info; }
8}
9 
10function ts() { return new Date().toISOString(); }
11 
12function debug(...a) { if (LEVELS.debug >= threshold()) console.log(ts(), 'debug', ...a); }
13function info(...a) { if (LEVELS.info >= threshold()) console.log(ts(), 'info', ...a); }
14function warn(...a) { if (LEVELS.warn >= threshold()) console.warn(ts(), 'warn', ...a); }
15function error(...a) { if (LEVELS.error >= threshold()) console.error(ts(), 'error', ...a); }
16 
17module.exports = { debug, info, warn, error };
18 
Done 🔒 Internet