forked from loowid/loowid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.js
33 lines (29 loc) · 867 Bytes
/
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
'use strict';
var log4js = require('log4js');
var loggers = [];
function isValidLogLevel(str) {
return str === 'FATAL' || str === 'ERROR' || str === 'WARN' || str === 'INFO' || str === 'DEBUG' || str === 'TRACE';
}
module.exports.getLog = function(appender) {
var logger = log4js.getLogger(appender);
logger.setLevel('INFO');
loggers.push(logger);
return logger;
};
module.exports.setLogLevel = function(level,appender) {
if (isValidLogLevel(level)) {
for (var i=0; i<loggers.length; i+=1) {
if (!appender || appender === loggers[i].category) {
loggers[i].setLevel(level);
}
}
}
};
module.exports.printLogLevels = function(res) {
var response = '';
for (var i=0; i<loggers.length; i+=1) {
response += '['+loggers[i].category+']::'+loggers[i].level.levelStr+'<br>';
loggers[i].info(loggers[i].level.levelStr);
}
res.send(response);
};