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: implement node:logger · nodejs/node@71d82d2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • benchmark/logger
    • console-provider.js
    • creation.js
    • disabled.js
    • enabled.js
  • doc
    • api
      • cli.md
      • fs.md
      • index.md
      • logger.md
      • process.md
    • node.1
  • lib
    • internal
      • bootstrap
        • realm.js
      • process
        • pre_execution.js
      • streams
        • fast-utf8-stream.js
    • logger.js
  • src
    • node_builtins.cc
    • node_options.cc
    • node_options.h
  • test
    • benchmark
      • test-benchmark-logger.js
    • module-hooks
      • test-module-hooks-builtin-require.js
      • test-module-hooks-load-builtin-require.js
    • parallel
      • test-fastutf8stream-flush-sync.js
      • test-fastutf8stream-flush.js
      • test-fastutf8stream-periodicflush.js
      • test-logger-console-provider.js
      • test-logger-diagnostics-provider.js
      • test-logger-level-dispatch.js
      • test-logger.js
      • test-module-builtin-experimental.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎benchmark/logger/console-provider.js‎

Copy file name to clipboard
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
// End-to-end cost of logging through ConsoleProvider with the default JSON
4+
// serializer. The provider's stream write() is replaced to avoid I/O latency.
5+
6+
const common = require('../common.js');
7+
8+
const bench = common.createBenchmark(main, {
9+
n: [5e5],
10+
variant: ['json', 'flatten-pid', 'error'],
11+
}, {
12+
flags: ['--experimental-logger', '--no-warnings'],
13+
});
14+
15+
function main({ n, variant }) {
16+
const { ConsoleProvider, create } = require('node:logger');
17+
18+
const provider = new ConsoleProvider({
19+
flatten: variant === 'flatten-pid',
20+
pid: variant === 'flatten-pid',
21+
});
22+
let bytes = 0;
23+
provider.stream.write = (data) => {
24+
bytes += data.length;
25+
return true;
26+
};
27+
const logger = create(provider, {
28+
name: 'bench',
29+
bindings: { service: 'api' },
30+
});
31+
32+
if (variant === 'error') {
33+
const err = new Error('boom');
34+
err.code = 'E_BOOM';
35+
bench.start();
36+
for (let i = 0; i < n; i++) logger.error('failed', { err });
37+
bench.end(n);
38+
} else {
39+
bench.start();
40+
for (let i = 0; i < n; i++) logger.info('hello', { i, user: 'x' });
41+
bench.end(n);
42+
}
43+
44+
if (bytes === 0) throw new Error('nothing was serialized');
45+
}
Collapse file

‎benchmark/logger/creation.js‎

Copy file name to clipboard
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
// Cost of creating loggers and child loggers.
4+
5+
const common = require('../common.js');
6+
7+
const bench = common.createBenchmark(main, {
8+
n: [1e6],
9+
type: ['create', 'child'],
10+
}, {
11+
flags: ['--experimental-logger', '--no-warnings'],
12+
});
13+
14+
function main({ n, type }) {
15+
const { ConsoleProvider, create } = require('node:logger');
16+
17+
const provider = new ConsoleProvider();
18+
const parent = create(provider, { name: 'bench' });
19+
const loggers = new Array(1024);
20+
21+
if (type === 'child') {
22+
bench.start();
23+
for (let i = 0; i < n; i++) {
24+
loggers[i & 1023] = parent.child({ requestId: i });
25+
}
26+
bench.end(n);
27+
} else {
28+
bench.start();
29+
for (let i = 0; i < n; i++) {
30+
loggers[i & 1023] = create(provider, { name: 'bench' });
31+
}
32+
bench.end(n);
33+
}
34+
}
Collapse file

‎benchmark/logger/disabled.js‎

Copy file name to clipboard
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
// Calls to level methods for a level the provider has disabled.
4+
5+
const common = require('../common.js');
6+
7+
const bench = common.createBenchmark(main, {
8+
n: [1e8],
9+
provider: ['console', 'custom'],
10+
attributes: ['none', 'object'],
11+
child: [0, 1],
12+
}, {
13+
flags: ['--experimental-logger', '--no-warnings'],
14+
});
15+
16+
function main({ n, provider, attributes, child }) {
17+
const { ConsoleProvider, create } = require('node:logger');
18+
19+
let logger = create(provider === 'console' ?
20+
new ConsoleProvider({ level: 'info' }) :
21+
{
22+
isEnabled(level) { return level.value >= 30; },
23+
log() {},
24+
});
25+
if (child) logger = logger.child({ requestId: 1 });
26+
27+
if (attributes === 'object') {
28+
bench.start();
29+
for (let i = 0; i < n; i++) logger.debug('hello', { i });
30+
bench.end(n);
31+
} else {
32+
bench.start();
33+
for (let i = 0; i < n; i++) logger.debug('hello');
34+
bench.end(n);
35+
}
36+
}
Collapse file

‎benchmark/logger/enabled.js‎

Copy file name to clipboard
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
// Cost of composing an enabled log event, with a provider that does no work.
4+
5+
const common = require('../common.js');
6+
7+
const bench = common.createBenchmark(main, {
8+
n: [1e6],
9+
provider: ['minimal', 'custom'],
10+
variant: ['no-attributes', 'attributes', 'function-binding'],
11+
}, {
12+
flags: ['--experimental-logger', '--no-warnings'],
13+
});
14+
15+
function main({ n, provider, variant }) {
16+
const { create } = require('node:logger');
17+
const { AsyncLocalStorage } = require('node:async_hooks');
18+
19+
let last;
20+
const log = (event) => { last = event; };
21+
const als = new AsyncLocalStorage();
22+
const bindings = variant === 'function-binding' ?
23+
{ service: 'api', request: () => als.getStore() } :
24+
{ service: 'api' };
25+
const logger = create(provider === 'minimal' ? { log } : {
26+
isEnabled(level) { return level.value >= 30; },
27+
log,
28+
}, { name: 'bench', bindings });
29+
30+
switch (variant) {
31+
case 'no-attributes':
32+
bench.start();
33+
for (let i = 0; i < n; i++) logger.info('hello');
34+
bench.end(n);
35+
break;
36+
case 'attributes':
37+
bench.start();
38+
for (let i = 0; i < n; i++) logger.info('hello', { i, user: 'x' });
39+
bench.end(n);
40+
break;
41+
case 'function-binding':
42+
als.enterWith(1);
43+
bench.start();
44+
for (let i = 0; i < n; i++) logger.info('hello', { i });
45+
bench.end(n);
46+
break;
47+
}
48+
49+
if (last === undefined) throw new Error('no event was logged');
50+
}
Collapse file

‎doc/api/cli.md‎

Copy file name to clipboardExpand all lines: doc/api/cli.md
+12Lines changed: 12 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,16 @@ Specify the `module` containing exported [asynchronous module customization hook
15451545

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

1548+
### `--experimental-logger`
1549+
1550+
<!-- YAML
1551+
added: REPLACEME
1552+
-->
1553+
1554+
> Stability: 1.1 - Active development
1555+
1556+
Enable the experimental [`node:logger`][] module.
1557+
15481558
### `--experimental-network-inspection`
15491559

15501560
<!-- YAML
@@ -4276,6 +4286,7 @@ one is included in the list below.
42764286
* `--experimental-import-text`
42774287
* `--experimental-json-modules`
42784288
* `--experimental-loader`
4289+
* `--experimental-logger`
42794290
* `--experimental-modules`
42804291
* `--experimental-package-map`
42814292
* `--experimental-print-required-tla`
@@ -4961,6 +4972,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
49614972
[`inspector.open()`]: inspector.md#inspectoropenport-host-wait
49624973
[`net.getDefaultAutoSelectFamilyAttemptTimeout()`]: net.md#netgetdefaultautoselectfamilyattempttimeout
49634974
[`node:ffi`]: ffi.md
4975+
[`node:logger`]: logger.md
49644976
[`node:sqlite`]: sqlite.md
49654977
[`node:stream/iter`]: stream_iter.md
49664978
[`node:vfs`]: vfs.md
Collapse file

‎doc/api/fs.md‎

Copy file name to clipboardExpand all lines: doc/api/fs.md
+4-3Lines changed: 4 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -8563,12 +8563,13 @@ Close the stream gracefully, flushing the internal buffer before closing.
85638563
* `callback` {Function}
85648564
* `err` {Error|null} An error if the flush failed, otherwise `null`.
85658565
8566-
Writes the current buffer to the file if a write was not in progress. Do
8567-
nothing if `minLength` is zero or if it is already writing.
8566+
Writes the current buffer to the file. The callback is invoked after pending
8567+
writes complete.
85688568
85698569
#### `utf8Stream.flushSync()`
85708570
8571-
Flushes the buffered data synchronously. This is a costly operation.
8571+
Flushes the buffered data synchronously. This is a costly operation. An
8572+
`ERR_INVALID_STATE` error is thrown if the stream is currently writing.
85728573
85738574
#### `utf8Stream.fsync`
85748575
Collapse file

‎doc/api/index.md‎

Copy file name to clipboardExpand all lines: doc/api/index.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
You are visitor 01402792 — 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.