diff --git a/.travis.yml b/.travis.yml index 81a93a6..a9eeacc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: node_js sudo: false node_js: + - "6" - "5" - "4" - "0.12" diff --git a/lib/layouts.js b/lib/layouts.js index 66d7dd1..75b6e1e 100644 --- a/lib/layouts.js +++ b/lib/layouts.js @@ -3,6 +3,7 @@ var dateFormat = require('./date_format') , os = require('os') , eol = os.EOL || '\n' , util = require('util') +, semver = require('semver') , replacementRegExp = /%[sdj]/g , layoutMakers = { "messagePassThrough": function() { return messagePassThroughLayout; }, @@ -28,7 +29,13 @@ var dateFormat = require('./date_format') function wrapErrorsWithInspect(items) { return items.map(function(item) { if ((item instanceof Error) && item.stack) { - return { inspect: function() { return util.format(item) + '\n' + item.stack; } }; + return { inspect: function() { + if (semver.satisfies(process.version, '>=6')) { + return util.format(item); + } else { + return util.format(item) + '\n' + item.stack; + } + } }; } else { return item; } diff --git a/test/layouts-test.js b/test/layouts-test.js index 56be821..1b7d2ef 100644 --- a/test/layouts-test.js +++ b/test/layouts-test.js @@ -2,6 +2,7 @@ var vows = require('vows') , assert = require('assert') , os = require('os') +, semver = require('semver') , EOL = os.EOL || '\n'; //used for patternLayout tests. @@ -108,7 +109,7 @@ vows.describe('log4js layouts').addBatch({ }); }, 'should print error the contained error message': function(layoutOutput) { - var m = layoutOutput.match(/\{ \[Error: My Unique Error Message\]/); + var m = layoutOutput.match(/Error: My Unique Error Message/); assert.isArray(m); }, 'should print error augmented string attributes': function(layoutOutput) { @@ -142,7 +143,7 @@ vows.describe('log4js layouts').addBatch({ 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, + var i, layout = args[0], event = args[1], output, lines, error = new Error("Some made-up error"), stack = error.stack.split(/\n/); @@ -150,15 +151,26 @@ vows.describe('log4js layouts').addBatch({ output = layout(event); lines = output.split(/\n/); - assert.equal(lines.length - 1, stack.length); - assert.equal( - lines[0], - "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test [Error: Some made-up error]" - ); - - for (var i = 1; i < stack.length; i++) { - assert.equal(lines[i+2], stack[i+1]); + if (semver.satisfies(process.version, '>=6')) { + assert.equal(lines.length, stack.length); + assert.equal( + lines[0], + "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test Error: Some made-up error" + ); + for (i = 1; i < stack.length; i++) { + assert.equal(lines[i], stack[i]); + } + } else { + assert.equal(lines.length - 1, stack.length); + assert.equal( + lines[0], + "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test [Error: Some made-up error]" + ); + for (i = 1; i < stack.length; i++) { + assert.equal(lines[i+2], stack[i+1]); + } } + }, 'should output any extra data in the log event as util.inspect strings': function(args) { var layout = args[0], event = args[1], output, lines;