forked from rudderlabs/rudder-transformer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.js
42 lines (35 loc) · 1016 Bytes
/
logger.js
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
35
36
37
38
39
40
41
42
/* istanbul ignore file */
const levelDebug = 0; // Most verbose logging level
const levelInfo = 1; // Logs about state of the application
const levelWarn = 2; // Logs about warnings which dont immediately halt the application
const levelError = 3; // Logs about errors which dont immediately halt the application
// any value greater than levelError will work as levelNone
const logLevel = process.env.LOG_LEVEL
? parseInt(process.env.LOG_LEVEL, 10)
: levelInfo;
const debug = (msg, ...optionalParams) => {
if (levelDebug >= logLevel) {
console.debug(msg, optionalParams);
}
};
const info = (msg, ...optionalParams) => {
if (levelInfo >= logLevel) {
console.info(msg, optionalParams);
}
};
const warn = (msg, ...optionalParams) => {
if (levelWarn >= logLevel) {
console.warn(msg, optionalParams);
}
};
const error = (msg, ...optionalParams) => {
if (levelError >= logLevel) {
console.error(msg, optionalParams);
}
};
module.exports = {
debug,
info,
warn,
error
};