Skip to content

Commit

Permalink
doc: add esm examples to node:console
Browse files Browse the repository at this point in the history
PR-URL: #54108
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
mfdebian authored and targos committed Oct 2, 2024
1 parent c61cee2 commit 24976bf
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions doc/api/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ The `Console` class can be used to create a simple logger with configurable
output streams and can be accessed using either `require('node:console').Console`
or `console.Console` (or their destructured counterparts):

```js
```mjs
import { Console } from 'node:console';
```

```cjs
const { Console } = require('node:console');
```

Expand Down Expand Up @@ -132,7 +136,28 @@ 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
error output. If `stderr` is not provided, `stdout` is used for `stderr`.

```js
```mjs
import { createWriteStream } from 'node:fs';
import { Console } from 'node:console';
// Alternatively
// const { Console } = console;

const output = createWriteStream('./stdout.log');
const errorOutput = createWriteStream('./stderr.log');
// Custom simple logger
const logger = new Console({ stdout: output, stderr: errorOutput });
// use it like console
const count = 5;
logger.log('count: %d', count);
// In stdout.log: count 5
```

```cjs
const fs = require('node:fs');
const { Console } = require('node:console');
// Alternatively
// const { Console } = console;

const output = fs.createWriteStream('./stdout.log');
const errorOutput = fs.createWriteStream('./stderr.log');
// Custom simple logger
Expand Down

0 comments on commit 24976bf

Please sign in to comment.