-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlogger.js
More file actions
36 lines (28 loc) · 760 Bytes
/
logger.js
File metadata and controls
36 lines (28 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Simple logging utility
*/
const { config } = require('./config');
const LOG_LEVELS = {
debug: 0,
info: 1,
warn: 2,
error: 3,
};
const currentLevel = LOG_LEVELS[config.logLevel] || LOG_LEVELS.info;
function log(level, message, data = null) {
if (LOG_LEVELS[level] >= currentLevel) {
const timestamp = new Date().toISOString();
const logMessage = `[${timestamp}] [${level.toUpperCase()}] ${message}`;
if (data) {
console.log(logMessage, data);
} else {
console.log(logMessage);
}
}
}
module.exports = {
debug: (msg, data) => log('debug', msg, data),
info: (msg, data) => log('info', msg, data),
warn: (msg, data) => log('warn', msg, data),
error: (msg, data) => log('error', msg, data),
};