diff --git a/README.md b/README.md index c715858e6..59f5cfaac 100644 --- a/README.md +++ b/README.md @@ -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); @@ -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); diff --git a/lib/winston/common.js b/lib/winston/common.js index 37ef3fb89..5ce29376b 100644 --- a/lib/winston/common.js +++ b/lib/winston/common.js @@ -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, @@ -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) diff --git a/lib/winston/transports/console.js b/lib/winston/transports/console.js index c368dd460..ae662d8fe 100644 --- a/lib/winston/transports/console.js +++ b/lib/winston/transports/console.js @@ -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; diff --git a/lib/winston/transports/daily-rotate-file.js b/lib/winston/transports/daily-rotate-file.js index 29ea8323d..59d1ce058 100644 --- a/lib/winston/transports/daily-rotate-file.js +++ b/lib/winston/transports/daily-rotate-file.js @@ -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; @@ -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'; diff --git a/lib/winston/transports/file.js b/lib/winston/transports/file.js index 965ccc4ae..ead359eca 100644 --- a/lib/winston/transports/file.js +++ b/lib/winston/transports/file.js @@ -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; diff --git a/lib/winston/transports/memory.js b/lib/winston/transports/memory.js index 2a1ea9684..48e267444 100644 --- a/lib/winston/transports/memory.js +++ b/lib/winston/transports/memory.js @@ -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;