mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Corrected based on knolleary's comments.
This commit is contained in:
parent
276d893198
commit
deaef3ab86
29
red/log.js
29
red/log.js
@ -47,11 +47,6 @@ var LogHandler = function(settings) {
|
||||
this.metricsOn = settings ? settings.metrics||false : false;
|
||||
metricsEnabled = this.metricsOn;
|
||||
this.handler = (settings && settings.handler) ? settings.handler(settings) : consoleLogger;
|
||||
//if (settings && settings.handler) {
|
||||
//this.handler = settings.handler(settings);
|
||||
//} else {
|
||||
//this.handler = consoleLogger;
|
||||
//}
|
||||
this.on("log",function(msg) {
|
||||
if (this.shouldReportMessage(msg.level)) {
|
||||
this.handler(msg);
|
||||
@ -84,17 +79,21 @@ var log = module.exports = {
|
||||
init: function(settings) {
|
||||
logHandlers = [];
|
||||
var loggerSettings = {};
|
||||
var keys = Object.keys(settings.logging);
|
||||
if (keys.length === 0) {
|
||||
log.addHandler(new LogHandler());
|
||||
} else {
|
||||
for (var i=0, l=keys.length; i<l; i++) {
|
||||
var config = settings.logging[keys[i]];
|
||||
loggerSettings = config || {};
|
||||
//if ((keys[i] === "console") || config.handler) {
|
||||
log.addHandler(new LogHandler(loggerSettings));
|
||||
//}
|
||||
if (settings.logging) {
|
||||
var keys = Object.keys(settings.logging);
|
||||
if (keys.length === 0) {
|
||||
log.addHandler(new LogHandler());
|
||||
} else {
|
||||
for (var i=0, l=keys.length; i<l; i++) {
|
||||
var config = settings.logging[keys[i]];
|
||||
loggerSettings = config || {};
|
||||
if ((keys[i] === "console") || config.handler) {
|
||||
log.addHandler(new LogHandler(loggerSettings));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.addHandler(new LogHandler());
|
||||
}
|
||||
},
|
||||
addHandler: function(func) {
|
||||
|
@ -144,7 +144,7 @@ describe("red/log", function() {
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[trace] This is a trace");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[metric] ");
|
||||
});
|
||||
it('uses console logger if custom logger handler does not exist', function() {
|
||||
it('no logger used if custom logger handler does not exist', function() {
|
||||
var settings = {logging: { customLogger: { level: 'trace', metrics: true } } };
|
||||
log.init(settings);
|
||||
log.error("This is an error");
|
||||
@ -153,11 +153,11 @@ describe("red/log", function() {
|
||||
log.debug("This is a debug");
|
||||
log.trace("This is a trace");
|
||||
log.log({level:log.METRIC,msg:"testMetric"});
|
||||
sinon.assert.calledWithMatch(util.log,"[error] This is an error");
|
||||
sinon.assert.calledWithMatch(util.log,"[warn] This is a warn");
|
||||
sinon.assert.calledWithMatch(util.log,"[info] This is an info");
|
||||
sinon.assert.calledWithMatch(util.log,"[debug] This is a debug");
|
||||
sinon.assert.calledWithMatch(util.log,"[trace] This is a trace");
|
||||
sinon.assert.calledWithMatch(util.log,"[metric] ");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[error] This is an error");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[warn] This is a warn");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[info] This is an info");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[debug] This is a debug");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[trace] This is a trace");
|
||||
sinon.assert.neverCalledWithMatch(util.log,"[metric] ");
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user