GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: added logger api to node core by mertcanaltin · Pull Request #60468 · nodejs/node

lib: added logger api to node core #60468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mertcanaltin wants to merge 31 commits into nodejs:main from mertcanaltin:mert/create-logger-api/node-core

Uh oh!

There was an error while loading. Please reload this page.

Closed

lib: added logger api to node core #60468

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
179e2d1
lib: add logger api in node core
mertcanaltin Feb 26, 2026
c658b21
lib: address review feedback for logger API
mertcanaltin Feb 26, 2026
a8603fb
lib: address review feedback for logger API
mertcanaltin Feb 26, 2026
95089ef
added missing test
mertcanaltin Feb 26, 2026
8be7bcf
logger: address review feedback
mertcanaltin Feb 27, 2026
c9282ef
logger: address review feedback
mertcanaltin Feb 27, 2026
04ec44c
Update lib/internal/logger/serializers.js
mertcanaltin Feb 27, 2026
4b361f7
delete pino benchmark
mertcanaltin Feb 27, 2026
b900393
delete exports (LEVELS, channels)
mertcanaltin Feb 27, 2026
36b1edd
edited logger api md
mertcanaltin Mar 29, 2026
14b0a3a
address review feedback for logger api
mertcanaltin Apr 5, 2026
87cbfa1
logger: skip input validation when no subscribers
mertcanaltin Apr 15, 2026
1f897fc
doc: address review feedback on logger.md
mertcanaltin Apr 15, 2026
3c24799
doc: add log channels in diagnostics_channel
mertcanaltin Apr 15, 2026
e58be5f
Update serializers.js
mertcanaltin Apr 15, 2026
4563bc2
Update serializers.js
mertcanaltin Apr 15, 2026
b4ceb0a
Update logger.js
mertcanaltin Apr 15, 2026
3e8166d
Update lib/internal/logger/serializers.js
mertcanaltin Apr 15, 2026
796f6b3
Merge branch 'main' into mert/create-logger-api/node-core
mertcanaltin Apr 19, 2026
700566b
logger: address review feedback
mertcanaltin Apr 19, 2026
42ae3a8
Merge branch 'main' into mert/create-logger-api/node-core
mertcanaltin Apr 20, 2026
b686bee
src: remove duplicate experimental_stream_iter
mertcanaltin Apr 22, 2026
d4f75da
Merge branch 'main' into mert/create-logger-api/node-core
mertcanaltin May 26, 2026
2e64414
use single diagnostics channel with consumer-side filtering
mertcanaltin Jun 27, 2026
98f3e5a
updated doc
mertcanaltin Jun 27, 2026
8ddfad1
apply serializers to bindings in Logger constructor
mertcanaltin Jun 27, 2026
dfe69ff
remove double serialize
mertcanaltin Jun 28, 2026
1108c7e
simplify bindings handling in child logger creation
mertcanaltin Jun 28, 2026
f38c709
add default error serializers to logger class
mertcanaltin Jun 28, 2026
9641dc6
Merge branch 'main' into mert/create-logger-api/node-core
mertcanaltin Aug 13, 2026
1a1c110
doc: regenerate node.1
mertcanaltin Aug 13, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

174 changes: 174 additions & 0 deletions 174 benchmark/logger/basic-json.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
'use strict';

const common = require('../common');
const fs = require('node:fs');

const bench = common.createBenchmark(main, {
n: [1e5],
scenario: [
'string-short',
'string-long',
'object-simple',
'object-nested',
'object-array',
'object-mixed',
'child-logger',
'disabled-level',
'error-object',
],
});

function main({ n, scenario }) {
const { Logger, JSONConsumer } = require('node:logger');

const nullFd = fs.openSync('/dev/null', 'w');
const consumer = new JSONConsumer({ stream: nullFd, level: 'info' });
consumer.attach();

const logger = new Logger({ level: 'info' });

switch (scenario) {
case 'string-short': {
// Simple short string message
bench.start();
for (let i = 0; i < n; i++) {
logger.info('hello');
}
bench.end(n);
break;
}

case 'string-long': {
// Long string message (100 chars)
const longMsg = 'This is a much longer log message that contains ' +
'more text to serialize and process during logging operations';
bench.start();
for (let i = 0; i < n; i++) {
logger.info(longMsg);
}
bench.end(n);
break;
}

case 'object-simple': {
// Object with msg and a few string fields
bench.start();
for (let i = 0; i < n; i++) {
logger.info({
msg: 'user action',
userId: 'user-123',
action: 'login',
});
Comment thread
Comment on lines +57 to +61

@Qard Qard Feb 4, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These object benchmarks would also be measuring the construction time of each object constructed within each loop iteration. Not sure if we care about that for this benchmark, but figured it was worth pointing out.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
}
bench.end(n);
break;
}

case 'object-nested': {
// Object with nested structure
bench.start();
for (let i = 0; i < n; i++) {
logger.info({
msg: 'request completed',
request: {
method: 'POST',
path: '/api/users',
headers: {
'content-type': 'application/json',
'user-agent': 'Mozilla/5.0',
},
},
response: {
statusCode: 200,
body: { success: true },
},
});
}
bench.end(n);
break;
}

case 'object-array': {
// Object with array fields
const tags = ['web', 'api', 'auth', 'production'];
const ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
bench.start();
for (let i = 0; i < n; i++) {
logger.info({
msg: 'batch operation',
tags,
processedIds: ids,
results: ['success', 'success', 'failed', 'success'],
});
}
bench.end(n);
break;
}

case 'object-mixed': {
// Mixed types: strings, numbers, booleans, null
bench.start();
for (let i = 0; i < n; i++) {
logger.info({
msg: 'mixed data',
stringField: 'value',
numberField: 42,
floatField: 3.14159,
booleanField: true,
nullField: null,
timestamp: 1704067200000,
});
}
bench.end(n);
break;
}

case 'child-logger': {
// Child logger with pre-bound context
const childLogger = logger.child({
service: 'api',
version: '1.0.0',
env: 'production',
});
bench.start();
for (let i = 0; i < n; i++) {
childLogger.info({
msg: 'request',
requestId: 'req-123',
duration: 150,
});
}
bench.end(n);
break;
}

case 'disabled-level': {
// Logging at disabled level (debug when level is info)
bench.start();
for (let i = 0; i < n; i++) {
logger.debug('this will be skipped');
}
bench.end(n);
break;
}

case 'error-object': {
// Logging with Error object
const error = new Error('Something went wrong');
error.code = 'ERR_SOMETHING';
bench.start();
for (let i = 0; i < n; i++) {
logger.error({
msg: 'operation failed',
err: error,
operation: 'database-query',
});
}
bench.end(n);
break;
}
}

consumer.flushSync();
fs.closeSync(nullFd);
}
13 changes: 13 additions & 0 deletions 13 doc/api/cli.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,17 @@ Specify the `module` containing exported [asynchronous module customization hook

This feature requires `--allow-worker` if used with the [Permission Model][].

### `--experimental-logger`

<!-- YAML
added: REPLACEME
-->

> Stability: 1.1 - Active Development

Enable the experimental `node:logger` module for structured logging.
See the [Logger][] documentation for more details.

### `--experimental-network-inspection`

<!-- YAML
Expand Down Expand Up @@ -3876,6 +3887,7 @@ one is included in the list below.
* `--experimental-import-text`
* `--experimental-json-modules`
* `--experimental-loader`
* `--experimental-logger`
* `--experimental-modules`
* `--experimental-package-map`
* `--experimental-print-required-tla`
Expand Down Expand Up @@ -4476,6 +4488,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
[FIPS mode]: crypto.md#fips-mode
[File System Permissions]: permissions.md#file-system-permissions
[Loading ECMAScript modules using `require()`]: modules.md#loading-ecmascript-modules-using-require
[Logger]: logger.md
[Module resolution and loading]: packages.md#module-resolution-and-loading
[Navigator API]: globals.md#navigator
[Node.js issue tracker]: https://github.com/nodejs/node/issues
Expand Down
32 changes: 32 additions & 0 deletions 32 doc/api/diagnostics_channel.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,37 @@ passed to `console.warn()`.
Emitted when `console.error()` is called. Receives and array of the arguments
passed to `console.error()`.

#### Logger

> Stability: 1.1 - Active Development

Published by the [`node:logger`][] module. Each log level has its own channel,
allowing subscribers to filter by severity without matching on record contents.

##### Event: `'log:trace'`

* `record` {Object} Log record emitted at the `trace` level.

##### Event: `'log:debug'`

* `record` {Object} Log record emitted at the `debug` level.

##### Event: `'log:info'`

* `record` {Object} Log record emitted at the `info` level.

##### Event: `'log:warn'`

* `record` {Object} Log record emitted at the `warn` level.

##### Event: `'log:error'`

* `record` {Object} Log record emitted at the `error` level.

##### Event: `'log:fatal'`

* `record` {Object} Log record emitted at the `fatal` level.

#### HTTP

> Stability: 1 - Experimental
Expand Down Expand Up @@ -1945,6 +1976,7 @@ Emitted when a new thread is created.
[`error` event]: #errorevent
[`locks.request()`]: worker_threads.md#locksrequestname-options-callback
[`net.Server.listen()`]: net.md#serverlisten
[`node:logger`]: logger.md
[`process.execve()`]: process.md#processexecvefile-args-env
[`start` event]: #startevent
[`worker_threads.locks`]: worker_threads.md#worker_threadslocks
Expand Down
1 change: 1 addition & 0 deletions 1 doc/api/index.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
* [UDP/datagram](dgram.md)
* [URL](url.md)
* [Utilities](util.md)
* [Logger](logger.md)
* [V8](v8.md)
* [Virtual File System](vfs.md)
* [VM](vm.md)
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.