From 0c93b221f4aa0c16001bc420bdee59d78ffc1ca1 Mon Sep 17 00:00:00 2001 From: David Townshend Date: Wed, 26 Aug 2015 16:52:50 +0200 Subject: [PATCH 1/2] Add a test for setting the end-of-line character --- test/transports/console-test.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/transports/console-test.js b/test/transports/console-test.js index 923a6d626..d2998e4cf 100644 --- a/test/transports/console-test.js +++ b/test/transports/console-test.js @@ -63,6 +63,20 @@ vows.describe('winston/transports/console').addBatch({ assert.isNull(err); assert.isTrue(logged); }) + }, + "with end-of-line": { + topic : function() { + npmTransport.endOfLine = 'X'; + stdMocks.use(); + npmTransport.log('info', ''); + }, + "should have end-of-line character appended": function () { + stdMocks.restore(); + var output = stdMocks.flush(), + line = output.stdout[0]; + + assert.equal(line, 'info: X'); + } } } -}).export(module); \ No newline at end of file +}).export(module); From 1c42155d14c3db65bf08bfd7c10484355d938a8b Mon Sep 17 00:00:00 2001 From: David Townshend Date: Wed, 26 Aug 2015 16:55:38 +0200 Subject: [PATCH 2/2] Add an endOfLine option to the console transport --- lib/winston/transports/console.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/winston/transports/console.js b/lib/winston/transports/console.js index 0aba87693..8751e0230 100644 --- a/lib/winston/transports/console.js +++ b/lib/winston/transports/console.js @@ -30,6 +30,7 @@ var Console = exports.Console = function (options) { this.logstash = options.logstash || false; this.debugStdout = options.debugStdout || false; this.depth = options.depth || null; + this.endOfLine = options.endOfLine || '\n'; if (this.json) { this.stringify = options.stringify || function (obj) { @@ -83,9 +84,9 @@ Console.prototype.log = function (level, msg, meta, callback) { }); if (level === 'error' || (level === 'debug' && !this.debugStdout) ) { - process.stderr.write(output + '\n'); + process.stderr.write(output + this.endOfLine); } else { - process.stdout.write(output + '\n'); + process.stdout.write(output + this.endOfLine); } //