forked from openhab/openhab-alexa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.js
52 lines (49 loc) · 1.08 KB
/
log.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
43
44
45
46
47
48
49
50
51
52
/**
* Logging helpers for lambda
* Set enviroment variable LOG_LEVEL to one of the following LEVELS to control
* verbosity of logging.
*/
var LEVELS = [
'TRACE',
'DEBUG',
'INFO',
'WARN',
'ERROR',
];
var DEFAULT = 'DEBUG';
function log(level, message) {
var setLevel = LEVELS.indexOf(process.env.LOG_LEVEL ?
process.env.LOG_LEVEL : DEFAULT);
if (LEVELS.indexOf(level) < setLevel) {
return;
}
switch (level) {
case 'INFO':
console.info(message);
break;
case 'WARN':
console.warn(message);
break;
case 'ERROR':
console.error(message);
break;
default: // debug, trace
console.log(message);
break;
}
}
module.exports.trace = function (message) {
log('TRACE', message);
};
module.exports.debug = function (message) {
log('DEBUG', message);
};
module.exports.info = function (message) {
log('INFO', message);
};
module.exports.warn = function (message) {
log('WARN', message);
};
module.exports.error = function (message) {
log('ERROR', message);
};