diff --git a/spec/spec.logging.js b/spec/spec.logging.js index 0b91e5a..4e6f923 100644 --- a/spec/spec.logging.js +++ b/spec/spec.logging.js @@ -104,39 +104,8 @@ describe 'log4js' end end - describe 'basicLayout' - it 'should take a logevent and output a formatted string' - logger.debug('this is a test'); - var output = log4js.basicLayout(event); - output.should.match /\[.*?\] \[DEBUG\] tests - this is a test/ - end - - it 'should output a stacktrace, message if the event has an error attached' - var error = new Error("Some made-up error"); - var stack = error.stack.split(/\n/); - - logger.debug('this is a test', error); - - var output = log4js.basicLayout(event); - var lines = output.split(/\n/); - lines.length.should.be stack.length+1 - lines[0].should.match /\[.*?\] \[DEBUG\] tests - this is a test/ - lines[1].should.match /\[.*?\] \[DEBUG\] tests - Error: Some made-up error/ - for (var i = 1; i < stack.length; i++) { - lines[i+1].should.eql stack[i] - } - end - - it 'should output a name and message if the event has something that pretends to be an error' - logger.debug('this is a test', { name: 'Cheese', message: 'Gorgonzola smells.' }); - var output = log4js.basicLayout(event); - var lines = output.split(/\n/); - lines.length.should.be 2 - lines[0].should.match /\[.*?\] \[DEBUG\] tests - this is a test/ - lines[1].should.match /\[.*?\] \[DEBUG\] tests - Cheese: Gorgonzola smells./ - end - end + diff --git a/test/logging.js b/test/logging.js index 8fd9d8a..92d674e 100644 --- a/test/logging.js +++ b/test/logging.js @@ -327,6 +327,55 @@ vows.describe('log4js').addBatch({ } }, + 'basicLayout': { + topic: function() { + var layout = require('../lib/log4js')().basicLayout, + event = { + message: 'this is a test', + startTime: new Date(2010, 11, 5, 14, 18, 30, 45), + categoryName: "tests", + level: { + colour: "green", + toString: function() { return "DEBUG"; } + } + }; + return [layout, event]; + }, + 'should take a logevent and output a formatted string': function(args) { + var layout = args[0], event = args[1]; + assert.equal(layout(event), "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test"); + }, + 'should output a stacktrace, message if the event has an error attached': function(args) { + var layout = args[0], event = args[1], output, lines, + error = new Error("Some made-up error"), + stack = error.stack.split(/\n/); + + event.exception = error; + output = layout(event); + lines = output.split(/\n/); + + assert.length(lines, stack.length+1); + assert.equal(lines[0], "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test"); + assert.equal(lines[1], "[2010-12-05 14:18:30.045] [DEBUG] tests - Error: Some made-up error"); + for (var i = 1; i < stack.length; i++) { + assert.equal(lines[i+1], stack[i]); + } + }, + 'should output a name and message if the event has something that pretends to be an error': function(args) { + var layout = args[0], event = args[1], output, lines; + event.exception = { + name: 'Cheese', + message: 'Gorgonzola smells.' + }; + output = layout(event); + lines = output.split(/\n/); + + assert.length(lines, 2); + assert.equal(lines[0], "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test"); + assert.equal(lines[1], "[2010-12-05 14:18:30.045] [DEBUG] tests - Cheese: Gorgonzola smells."); + } + }, + 'logLevelFilter': { topic: function() { var log4js = require('../lib/log4js')(), logEvents = [], logger;