diff --git a/doc/api/console.md b/doc/api/console.md index d9736a7c9f1f15..59e5ae368569ff 100644 --- a/doc/api/console.md +++ b/doc/api/console.md @@ -60,9 +60,10 @@ changes: - version: v8.0.0 pr-url: https://github.com/nodejs/node/pull/9744 description: Errors that occur while writing to the underlying streams - will now be ignored. + will now be ignored by default. --> + The `Console` class can be used to create a simple logger with configurable @@ -77,9 +78,29 @@ const { Console } = require('console'); const { Console } = console; ``` -### new Console(stdout[, stderr]) -* `stdout` {stream.Writable} -* `stderr` {stream.Writable} +### new Console(stdout[, stderr][, ignoreErrors]) +### new Console(options) + + +* `options` {Object} + * `stdout` {stream.Writable} + * `stderr` {stream.Writable} + * `ignoreErrors` {boolean} Ignore errors when writing to the underlying + streams. **Default:** `true`. + * `colorMode` {boolean|string} Set color support for this `Console` instance. + Setting to `true` enables coloring while inspecting values, setting to + `'auto'` will make color support depend on the value of the `isTTY` property + and the value returned by `getColorDepth()` on the respective stream. + **Default:** `'auto'` 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 @@ -89,7 +110,7 @@ error output. If `stderr` is not provided, `stdout` is used for `stderr`. const output = fs.createWriteStream('./stdout.log'); const errorOutput = fs.createWriteStream('./stderr.log'); // custom simple logger -const logger = new Console(output, errorOutput); +const logger = new Console({ stdout: output, stderr: errorOutput }); // use it like console const count = 5; logger.log('count: %d', count); @@ -100,7 +121,7 @@ The global `console` is a special `Console` whose output is sent to [`process.stdout`][] and [`process.stderr`][]. It is equivalent to calling: ```js -new Console(process.stdout, process.stderr); +new Console({ stdout: process.stdout, stderr: process.stderr }); ``` ### console.assert(value[, ...message]) diff --git a/doc/api/util.md b/doc/api/util.md index effe5074d2be89..e8f97397d30b27 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -254,6 +254,24 @@ intended as a debugging tool. Some input values can have a significant performance overhead that can block the event loop. Use this function with care and never in a hot code path. +## util.formatWithOptions(inspectOptions, format[, ...args]) + + +* `inspectOptions` {Object} +* `format` {string} + +This function is identical to [`util.format()`][], except in that it takes +an `inspectOptions` argument which specifies options that are passed along to +[`util.inspect()`][]. + +```js +util.formatWithOptions({ colors: true }, 'See object %O', { foo: 42 }); +// Returns 'See object { foo: 42 }', where `42` is colored as a number +// when printed to a terminal. +``` + ## util.getSystemErrorName(err)