From c7e59ad238c40159957a33557264406f2e9a1695 Mon Sep 17 00:00:00 2001 From: Jarrett Cruger Date: Sun, 18 Oct 2015 13:08:08 -0400 Subject: [PATCH 1/2] [fix] properly log message when using `raw` mode --- lib/winston/common.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/winston/common.js b/lib/winston/common.js index 3ae52c057..2d5f81775 100644 --- a/lib/winston/common.js +++ b/lib/winston/common.js @@ -145,7 +145,16 @@ exports.log = function (options) { } output = exports.clone(meta) || {}; output.level = options.level; - output.message = options.message.stripColors; + // + // Remark (jcrugzz): This used to be output.message = options.message.stripColors. + // I do not know why this is, it does not make sense but im handling that + // case here as well as handling the case that does make sense which is to + // make the `output.message = options.message` + // + output.message = options.message.stripColors + ? options.message.stripColors + : options.message; + return JSON.stringify(output); } From 4450bf9505555fc0f0a3996dec47d735b3e96405 Mon Sep 17 00:00:00 2001 From: Jarrett Cruger Date: Sun, 18 Oct 2015 13:08:24 -0400 Subject: [PATCH 2/2] [test] test that raw mode works as expected --- test/transports/console-test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/transports/console-test.js b/test/transports/console-test.js index 107c9ca16..68425739a 100644 --- a/test/transports/console-test.js +++ b/test/transports/console-test.js @@ -17,6 +17,7 @@ var npmTransport = new (winston.transports.Console)(), syslogTransport = new (winston.transports.Console)({ levels: winston.config.syslog.levels }), alignTransport = new (winston.transports.Console)({ showLevel: true, align: true }), defaultTransport = new (winston.transports.Console)(), + rawTransport = new (winston.transports.Console)({ level: 'verbose', raw: true }), debugStdoutTransport = new (winston.transports.Console)({ debugStdout: true }), stderrLevelsTransport = new (winston.transports.Console)({ stderrLevels: ['info', 'warn'] }), customLevels = { @@ -34,6 +35,7 @@ var npmTransport = new (winston.transports.Console)(), vows.describe('winston/transports/console').addBatch({ "An instance of the Console Transport": { + "with showLevel on": { topic : function() { npmTransport.showLevel = true; @@ -110,6 +112,19 @@ vows.describe('winston/transports/console').addBatch({ assert.equal(line, 'info: \n'); } } +}).addBatch({ + 'An instance of a raw Console transport': { + 'logging to stdout': { + topic: function () { + stdMocks.use(); + rawTransport.log('verbose', 'hello there'); + }, 'should output json with message property': function () { + stdMocks.restore(); + var output = stdMocks.flush(); + assert.ok(output.stdout[0].indexOf('"message":"hello there"') > -1); + } + } + } }).addBatch({ "An instance of the Console Transport with no options": { "should set stderrLevels to 'error' and 'debug' by default": helpers.assertStderrLevels(