diff --git a/lib/winston/common.js b/lib/winston/common.js index c1b94dfda..8ed997327 100644 --- a/lib/winston/common.js +++ b/lib/winston/common.js @@ -85,7 +85,7 @@ exports.clone = function (obj) { copy[key] = obj[key]; }); - return copy; + return cycle.decycle(copy); } else if (!(obj instanceof Object)) { return obj; @@ -145,7 +145,7 @@ exports.log = function (options) { : exports.timestamp, timestamp = options.timestamp ? timestampFn() : null, showLevel = options.showLevel === undefined ? true : options.showLevel, - meta = options.meta !== null && options.meta !== undefined && !(options.meta instanceof Error) + meta = options.meta !== null && options.meta !== undefined ? exports.clone(options.meta) : options.meta || null, output; @@ -244,10 +244,6 @@ exports.log = function (options) { : options.message; if (meta !== null && meta !== undefined) { - if (meta && meta instanceof Error && meta.stack) { - meta = meta.stack; - } - if (typeof meta !== 'object') { output += ' ' + meta; } diff --git a/test/helpers.js b/test/helpers.js index 8575fb69f..bb5bd55e3 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -194,6 +194,23 @@ helpers.testLevels = function (levels, transport, assertMsg, assertFn) { circmetadatatest[assertMsg] = assertFn; tests['when passed circular metadata'] = circmetadatatest; + var circerror = new Error("message!"); + var foo = {}; + var circerrordatatest; + + foo.bar = foo; + circerror.foo = foo; + circerror.stack = 'Some stacktrace'; + + circerrordatatest = { + topic: function () { + transport.log('info', 'test message', circerror, this.callback.bind(this, null)); + } + }; + + circerrordatatest[assertMsg] = assertFn; + tests['when passed circular error as metadata'] = circerrordatatest; + return tests; };