Skip to content

Commit efff647

Browse files
committed
lib: implement node:logger
A simpler attempt to add a structured logging API. Uses a provider model similar to VFS. This implements two providers out of the box, ConsoleProvider and ReadableProvider. ConsoleProvider is the default and uses Utf8Stream to emit to either stdout or stderr. ```js const { create } = require('node:logger'); const logger = create(); // default logger to console logger.info('foo'); // ... const als = new AsyncLocalStorage(); const logger2 = create(new ConsoleProvider({ pid: true }), { name: 'foo', bindings: { 'abc': 'included in every log line', 'xyz': als, // current als.getStore() included in // every log line } }); logger2.info('foo', { baz: 1 }); ``` The `Logger` keeps things as simple as possible, leaving actual handling of the log events to the providers, which can be fully customized. Easy to adapt to other loggers like pino or extend capabilities without directly touching the facade. Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode
1 parent 1e0ebef commit efff647

15 files changed

Lines changed: 2447 additions & 41 deletions

‎doc/api/fs.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8536,12 +8536,13 @@ Close the stream gracefully, flushing the internal buffer before closing.
85368536
* `callback` {Function}
85378537
* `err` {Error|null} An error if the flush failed, otherwise `null`.
85388538
8539-
Writes the current buffer to the file if a write was not in progress. Do
8540-
nothing if `minLength` is zero or if it is already writing.
8539+
Writes the current buffer to the file. The callback is invoked after pending
8540+
writes complete.
85418541
85428542
#### `utf8Stream.flushSync()`
85438543
8544-
Flushes the buffered data synchronously. This is a costly operation.
8544+
Flushes the buffered data synchronously. This is a costly operation. An
8545+
`ERR_INVALID_STATE` error is thrown if the stream is currently writing.
85458546
85468547
#### `utf8Stream.fsync`
85478548

‎doc/api/index.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* [Inspector](inspector.md)
3737
* [Internationalization](intl.md)
3838
* [Iterable Streams API](stream_iter.md)
39+
* [Logger](logger.md)
3940
* [Modules: CommonJS modules](modules.md)
4041
* [Modules: ECMAScript modules](esm.md)
4142
* [Modules: `node:module` API](module.md)

0 commit comments

Comments
 (0)