diff --git a/docs/transports.md b/docs/transports.md index 2b2b8b1d3..6352f0dd3 100644 --- a/docs/transports.md +++ b/docs/transports.md @@ -92,7 +92,8 @@ The Console transport takes a few simple options: * __silent:__ Boolean flag indicating whether to suppress output (default false). * __eol:__ string indicating the end-of-line characters to use (default `os.EOL`) * __stderrLevels__ Array of strings containing the levels to log to stderr instead of stdout, for example `['error', 'debug', 'info']`. (default `[]`) -* __consoleWarnLevels__ Array of strings containing the levels to log using console.warn or to stderr (in Node.js) instead of stdout, for example `['warn', 'debug']`. (default `[]`) +* __consoleLevels__ Map of levels to their corresponding console level (default: see [`Console`](../lib/winston/transports/console.js)) +* __consoleWarnLevels__ **DEPRECATED** Array of strings containing the levels to log using console.warn or to stderr (in Node.js) instead of stdout, for example `['warn', 'debug']`. (default `[]`) ### File Transport ``` js diff --git a/lib/winston/transports/console.js b/lib/winston/transports/console.js index b54f3da9c..32c611155 100644 --- a/lib/winston/transports/console.js +++ b/lib/winston/transports/console.js @@ -9,6 +9,7 @@ 'use strict'; const os = require('os'); +const inspector = require('inspector'); const { LEVEL, MESSAGE } = require('triple-beam'); const TransportStream = require('winston-transport'); @@ -30,6 +31,20 @@ module.exports = class Console extends TransportStream { this.name = options.name || 'console'; this.stderrLevels = this._stringArrayToSet(options.stderrLevels); this.consoleWarnLevels = this._stringArrayToSet(options.consoleWarnLevels); + this.consoleLevels = options.consoleLevels || { + emerg: 'error', + alert: 'error', + crit: 'error', + error: 'error', + warn: 'warn', + warning: 'warn', + notice: 'info', + info: 'info', + http: 'debug', + verbose: 'debug', + debug: 'debug', + silly: 'debug' + }; this.eol = (typeof options.eol === 'string') ? options.eol : os.EOL; this.setMaxListeners(30); @@ -49,6 +64,7 @@ module.exports = class Console extends TransportStream { if (console._stderr) { // Node.js maps `process.stderr` to `console._stderr`. console._stderr.write(`${info[MESSAGE]}${this.eol}`); + inspector.console[this.consoleLevels[info[LEVEL]] || 'error'](info[MESSAGE]); } else { // console.error adds a newline console.error(info[MESSAGE]); @@ -63,6 +79,7 @@ module.exports = class Console extends TransportStream { // Node.js maps `process.stderr` to `console._stderr`. // in Node.js console.warn is an alias for console.error console._stderr.write(`${info[MESSAGE]}${this.eol}`); + inspector.console.warn(info[MESSAGE]); } else { // console.warn adds a newline console.warn(info[MESSAGE]); @@ -77,6 +94,7 @@ module.exports = class Console extends TransportStream { if (console._stdout) { // Node.js maps `process.stdout` to `console._stdout`. console._stdout.write(`${info[MESSAGE]}${this.eol}`); + inspector.console[this.consoleLevels[info[LEVEL]] || 'log'](info[MESSAGE]); } else { // console.log adds a newline. console.log(info[MESSAGE]);