| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c61cee2 commit 24976bf
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,7 +80,11 @@ The `Console` class can be used to create a simple logger with configurable | |||
| 80 | 80 | output streams and can be accessed using either `require('node:console').Console` | |
| 81 | 81 | or `console.Console` (or their destructured counterparts): | |
| 82 | 82 | ||
| 83 | - ```js | ||
| 83 | + ```mjs | ||
| 84 | + import { Console } from 'node:console'; | ||
| 85 | + ``` | ||
| 86 | + | ||
| 87 | + ```cjs | ||
| 84 | 88 | const { Console } = require('node:console'); | |
| 85 | 89 | ``` | |
| 86 | 90 | ||
@@ -132,7 +136,28 @@ Creates a new `Console` with one or two writable stream instances. `stdout` is a | |||
| 132 | 136 | writable stream to print log or info output. `stderr` is used for warning or | |
| 133 | 137 | error output. If `stderr` is not provided, `stdout` is used for `stderr`. | |
| 134 | 138 | ||
| 135 | - ```js | ||
| 139 | + ```mjs | ||
| 140 | + import { createWriteStream } from 'node:fs'; | ||
| 141 | + import { Console } from 'node:console'; | ||
| 142 | + // Alternatively | ||
| 143 | + // const { Console } = console; | ||
| 144 | + | ||
| 145 | + const output = createWriteStream('./stdout.log'); | ||
| 146 | + const errorOutput = createWriteStream('./stderr.log'); | ||
| 147 | + // Custom simple logger | ||
| 148 | + const logger = new Console({ stdout: output, stderr: errorOutput }); | ||
| 149 | + // use it like console | ||
| 150 | + const count = 5; | ||
| 151 | + logger.log('count: %d', count); | ||
| 152 | + // In stdout.log: count 5 | ||
| 153 | + ``` | ||
| 154 | + | ||
| 155 | + ```cjs | ||
| 156 | + const fs = require('node:fs'); | ||
| 157 | + const { Console } = require('node:console'); | ||
| 158 | + // Alternatively | ||
| 159 | + // const { Console } = console; | ||
| 160 | + | ||
| 136 | 161 | const output = fs.createWriteStream('./stdout.log'); | |
| 137 | 162 | const errorOutput = fs.createWriteStream('./stderr.log'); | |
| 138 | 163 | // Custom simple logger | |
| Back | FazBrowse Home | New Git URL |
0 commit comments