8000 Fix for stack traces appearing twice in node v6 - issue #389 · JJediny/log4js-node@08315bb · GitHub
[go: up one dir, main page]

Skip to content

Commit 08315bb

Browse files
author
Gareth Jones
committed
Fix for stack traces appearing twice in node v6 - issue log4js-node#389
1 parent 60c48a5 commit 08315bb

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: node_js
22
sudo: false
33
node_js:
4+
- "6"
45
- "5"
56
- "4"
67
- "0.12"

lib/layouts.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var dateFormat = require('./date_format')
33
, os = require('os')
44
, eol = os.EOL || '\n'
55
, util = require('util')
6+
, semver = require('semver')
67
, replacementRegExp = /%[sdj]/g
78
, layoutMakers = {
89
"messagePassThrough": function() { return messagePassThroughLayout; },
@@ -28,7 +29,13 @@ var dateFormat = require('./date_format')
2829
function wrapErrorsWithInspect(items) {
2930
return items.map(function(item) {
3031
if ((item instanceof Error) && item.stack) {
31-
return { inspect: function() { return util.format(item) + '\n' + item.stack; } };
32+
return { inspect: function() {
33+
if (semver.satisfies(process.version, '>=6')) {
34+
return util.format(item);
35+
} else {
36+
return util.format(item) + '\n' + item.stack;
37+
}
38+
} };
3239
} else {
3340
return item;
3441
}

test/layouts-test.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var vows = require('vows')
33
, assert = require('assert')
44
, os = require('os')
5+
, semver = require('semver')
56
, EOL = os.EOL || '\n';
67

78
//used for patternLayout tests.
@@ -108,7 +109,7 @@ vows.describe('log4js layouts').addBatch({
108109
});
109110
},
110111
'should print error the contained error message': function(layoutOutput) {
111-
var m = layoutOutput.match(/\{ \[Error: My Unique Error Message\]/);
112+
var m = layoutOutput.match(/Error: My Unique Error Message/);
112113
assert.isArray(m);
113114
},
114115
'should print error augmented string attributes': function(layoutOutput) {
@@ -142,23 +143,34 @@ vows.describe('log4js layouts').addBatch({
142143
assert.equal(layout(event), "[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test");
143144
},
144145
'should output a stacktrace, message if the event has an error attached': function(args) {
145-
var layout = args[0], event = args[1], output, lines,
146+
var i, layout = args[0], event = args[1], output, lines,
146147
error = new Error("Some made-up error"),
147148
stack = error.stack.split(/\n/);
148149

149150
event.data = ['this is a test', error];
150151
output = layout(event);
151152
lines = output.split(/\n/);
152153

153-
assert.equal(lines.length - 1, stack.length);
154-
assert.equal(
155-
lines[0],
156-
"[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test [Error: Some made-up error]"
157-
);
158-
159-
for (var i = 1; i < stack.length; i++) {
160-
assert.equal(lines[i+2], stack[i+1]);
154+
if (semver.satisfies(process.version, '>=6')) {
155+
assert.equal(lines.length, stack.length);
156+
assert.equal(
157+
lines[0],
158+
"[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test Error: Some made-up error"
159+
);
160+
for (i = 1; i < stack.length; i++) {
161+
assert.equal(lines[i], stack[i]);
162+
}
163+
} else {
164+
assert.equal(lines.length - 1, stack.length);
165+
assert.equal(
166+
lines[0],
167+
"[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test [Error: Some made-up error]"
168+
);
169+
for (i = 1; i < stack.length; i++) {
170+
assert.equal(lines[i+2], stack[i+1]);
171+
}
161172
}
173+
162174
},
163175
'should output any extra data in the log event as util.inspect strings': function(args) {
164176
var layout = args[0], event = args[1], output, lines;

0 commit comments

Comments
 (0)
0