now handles exceptions that aren't Errors

This commit is contained in:
csausdev 2010-12-11 21:55:21 +11:00
parent c2f9ccce73
commit c870289928
2 changed files with 20 additions and 3 deletions

View File

@ -279,9 +279,13 @@ module.exports = function (fileSystem, standardOutput, configPaths) {
this.startTime = new Date();
this.categoryName = categoryName;
this.message = message;
this.exception = exception;
this.level = level;
this.logger = logger;
if (exception && exception.message && exception.name) {
this.exception = exception;
} else if (exception) {
this.exception = new Error(exception);
}
}
/**

View File

@ -29,6 +29,8 @@ vows.describe('log4js').addBatch({
logger.trace("Trace event 1");
logger.trace("Trace event 2");
logger.warn("Warning event");
logger.error("Aargh!", new Error("Pants are on fire!"));
logger.error("Simulated CouchDB problem", JSON.stringify({ err: 127, cause: "incendiary underwear" }));
return events;
},
@ -39,9 +41,20 @@ vows.describe('log4js').addBatch({
},
'should not emit events of a lower level': function(events) {
assert.length(events, 2);
assert.length(events, 4);
assert.equal(events[1].level.toString(), 'WARN');
}
},
'should include the error if passed in': function (events) {
assert.instanceOf(events[2].exception, Error);
assert.equal(events[2].exception.message, 'Pants are on fire!');
},
'should convert things that claim to be errors into Error objects': function (events) {
assert.instanceOf(events[3].exception, Error);
assert.equal(events[3].exception.message, '{"err":127,"cause":"incendiary underwear"}');
},
},
},