diff --git a/doc/api/console.md b/doc/api/console.md index 5c8b4ecc64d9b4..831ebd5070db40 100644 --- a/doc/api/console.md +++ b/doc/api/console.md @@ -127,6 +127,19 @@ changes: [`util.inspect()`][]. * `groupIndentation` {number} Set group indentation. **Default:** `2`. + * `highlight` {Object} With this option you can highlight outputs of + [`console.warn()`][] and [`console.error()`][]. It's not enabled by default, + and only affects when coloring is enabled. + * `warn` {Object} Highlight options for [`console.warn()`][]. + * `bgColor` {string} Background color used for highlighting, must be + one of the [`background colors`][] if not omitted. + * `indicator` {string} Optional leading string indicates if the output + is from [`console.warn()`][]. + * `error` {Object} Highlight options for [`console.error()`][]. + * `bgColor` {string} Background color used for highlighting, must be + one of the [`background colors`][] if not omitted. + * `indicator` {string} Optional leading string indicates if the output + is from [`console.error()`][]. Creates a new `Console` with one or two writable stream instances. `stdout` is a writable stream to print log or info output. `stderr` is used for warning or @@ -150,6 +163,25 @@ The global `console` is a special `Console` whose output is sent to new Console({ stdout: process.stdout, stderr: process.stderr }); ``` +You can create your own `Console` with highlighting: + +```js +const logger = new Console({ + stdout: process.stdout, + stderr: process.stderr, + highlight: { + warn: { bgColor: 'bgYellowBright' }, + error: { bgColor: 'bgRedBright', indicator: '\u274c' }, + } +}); + +logger.warn('Warning!'); +// Will output message 'Warning!' along with bright yellow background. +logger.error(new Error('Oops!')); +// Will output message 'Oops!' along with bright red background, +// and a unicode cross sign in front of the message indicating it is an error. +``` + ### `console.assert(value[, ...message])`