Skip to content

Commit

Permalink
Added showLevel flag to common.js, file*, memory and console transports.
Browse files Browse the repository at this point in the history
  • Loading branch information
CorbinDallas authored and indexzero committed Jan 27, 2015
1 parent c11ba87 commit 4c08191
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ The Console transport takes a few simple options:
* __timestamp:__ Boolean flag indicating if we should prepend output with timestamps (default false). If function is specified, its return value will be used instead of timestamps.
* __prettyPrint:__ Boolean flag indicating if we should `util.inspect` the meta (default false). If function is specified, its return value will be the string representing the meta.
* __depth__ Numeric indicating how many times to recurse while formatting the object with `util.inspect` (only used with `prettyPrint: true`) (default null, unlimited)
* __showLevel:__ Boolean flag indicating if we should prepend output with level (default true).

*Metadata:* Logged via util.inspect(meta);

Expand All @@ -666,6 +667,7 @@ The File transport should really be the 'Stream' transport since it will accept
* __prettyPrint:__ If true, additional JSON metadata objects that are added to logging string messages will be displayed as a JSON string representation. If function is specified, its return value will be the string representing the meta.
* __depth__ Numeric indicating how many times to recurse while formatting the object with `util.inspect` (only used with `prettyPrint: true`) (default null, unlimited)
* __logstash:__ If true, messages will be logged as JSON and formatted for logstash (default false).
* __showLevel:__ Boolean flag indicating if we should prepend output with level (default true).

*Metadata:* Logged via util.inspect(meta);

Expand Down
14 changes: 10 additions & 4 deletions lib/winston/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ exports.log = function (options) {
? options.timestamp
: 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)
? exports.clone(cycle.decycle(options.meta))
: options.meta || null,
Expand Down Expand Up @@ -189,12 +190,17 @@ exports.log = function (options) {
});
}

//
// Remark: this should really be a call to `util.format`.
//
output = timestamp ? timestamp + ' - ' : '';
output += options.colorize === 'all' || options.colorize === 'level' || options.colorize === true
? config.colorize(options.level)
: options.level;
if (showLevel) {
output += options.colorize === 'all' || options.colorize === 'level' || options.colorize === true
? config.colorize(options.level)
: options.level;
}

output += ': ';
output += (timestamp || showLevel) ? ': ' : '';
output += options.label ? ('[' + options.label + '] ') : '';
output += options.colorize === 'all' || options.colorize === 'message'
? config.colorize(options.level, options.message)
Expand Down
1 change: 1 addition & 0 deletions lib/winston/transports/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var Console = exports.Console = function (options) {
this.colorize = options.colorize || false;
this.prettyPrint = options.prettyPrint || false;
this.timestamp = typeof options.timestamp !== 'undefined' ? options.timestamp : false;
this.showLevel = options.showLevel === undefined ? true : options.showLevel;
this.label = options.label || null;
this.logstash = options.logstash || false;
this.debugStdout = options.debugStdout || false;
Expand Down
2 changes: 2 additions & 0 deletions lib/winston/transports/daily-rotate-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ var DailyRotateFile = exports.DailyRotateFile = function (options) {
this.maxFiles = options.maxFiles || null;
this.label = options.label || null;
this.prettyPrint = options.prettyPrint || false;
this.showLevel = options.showLevel === undefined ? true : options.showLevel;
this.timestamp = options.timestamp != null ? options.timestamp : true;
this.datePattern = options.datePattern != null ? options.datePattern : '.yyyy-MM-dd';
this.depth = options.depth || null;
Expand Down Expand Up @@ -158,6 +159,7 @@ DailyRotateFile.prototype.log = function (level, msg, meta, callback) {
timestamp: this.timestamp,
label: this.label,
stringify: this.stringify,
showLevel: this.showLevel,
depth: this.depth
}) + '\n';

Expand Down
1 change: 1 addition & 0 deletions lib/winston/transports/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ var File = exports.File = function (options) {
this.timestamp = options.timestamp != null ? options.timestamp : true;
this.eol = options.eol || '\n';
this.depth = options.depth || null;
this.showLevel = options.showLevel === undefined ? true : options.showLevel;

if (this.json) {
this.stringify = options.stringify;
Expand Down
1 change: 1 addition & 0 deletions lib/winston/transports/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var Memory = exports.Memory = function (options) {
this.colorize = options.colorize || false;
this.prettyPrint = options.prettyPrint || false;
this.timestamp = typeof options.timestamp !== 'undefined' ? options.timestamp : false;
this.showLevel = options.showLevel === undefined ? true : options.showLevel;
this.label = options.label || null;
this.depth = options.depth || null;

Expand Down

0 comments on commit 4c08191

Please sign in to comment.