Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align message level #623

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/winston/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ exports.clone = function (obj) {
// message: 'message to serialize',
// meta: 'additional logging metadata to serialize',
// colorize: false, // Colorizes output (only if `.json` is false)
// align: false // Align message level.
// timestamp: true // Adds a timestamp to the serialized message
// label: 'label to prepend the message'
// }
Expand Down Expand Up @@ -204,6 +205,7 @@ exports.log = function (options) {
: options.level;
}

output += (options.align) ? '\t' : '';
output += (timestamp || showLevel) ? ': ' : '';
output += options.label ? ('[' + options.label + '] ') : '';
output += options.colorize === 'all' || options.colorize === 'message'
Expand Down
2 changes: 2 additions & 0 deletions lib/winston/transports/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.align = options.align || false;

if (this.json) {
this.stringify = options.stringify || function (obj) {
Expand Down Expand Up @@ -79,6 +80,7 @@ Console.prototype.log = function (level, msg, meta, callback) {
logstash: this.logstash,
depth: this.depth,
formatter: this.formatter,
align: this.align,
humanReadableUnhandledException: this.humanReadableUnhandledException
});

Expand Down
32 changes: 31 additions & 1 deletion test/transports/console-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var path = require('path'),
stdMocks = require('std-mocks');

var npmTransport = new (winston.transports.Console)(),
syslogTransport = new (winston.transports.Console)({ levels: winston.config.syslog.levels });
syslogTransport = new (winston.transports.Console)({ levels: winston.config.syslog.levels }),
alignTransport = new (winston.transports.Console)({ showLevel: true, align: true });

vows.describe('winston/transports/console').addBatch({
"An instance of the Console Transport": {
Expand Down Expand Up @@ -65,4 +66,33 @@ vows.describe('winston/transports/console').addBatch({
})
}
}
}).addBatch({
"An instance of the Console Transport with the align option on": {
topic : function() {
stdMocks.use();
alignTransport.log('info', '');
},
"should have logs aligned": function () {
stdMocks.restore();
var output = stdMocks.flush(),
line = output.stdout[0];

assert.equal(line, 'info\011: \n');
}
}
}).addBatch({
"with align off": {
topic : function() {
alignTransport.align = false;
stdMocks.use();
alignTransport.log('info', '');
},
"should not have logs aligned": function () {
stdMocks.restore();
var output = stdMocks.flush(),
line = output.stdout[0];

assert.equal(line, 'info: \n');
}
}
}).export(module);