Skip to content

Commit 1975720

Browse files
authoredNov 26, 2021
Clarify that the "Exit logger" does not apply on Node v14+ (#1240)
Fixes #1232 Signed-off-by: Matteo Collina <hello@matteocollina.com>
1 parent 8ed597b commit 1975720

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed
 

‎docs/help.md

+33-29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Help
22

3-
* [Exit logging](#exit-logging)
43
* [Log rotation](#rotate)
54
* [Reopening log files](#reopening)
65
* [Saving to multiple files](#multiple)
@@ -13,34 +12,7 @@
1312
* [Unicode and Windows terminal](#windows)
1413
* [Mapping Pino Log Levels to Google Cloud Logging (Stackdriver) Serverity Levels](#stackdriver)
1514
* [Avoid Message Conflict](#avoid-message-conflict)
16-
17-
<a id="exit-logging"></a>
18-
## Exit logging
19-
20-
When a Node process crashes from uncaught exception, exits due to a signal,
21-
or exits of it's own accord we may want to write some final logs – particularly
22-
in cases of error.
23-
24-
Writing to a Node.js stream on exit is not necessarily guaranteed, and naively writing
25-
to an asynchronous logger on exit will definitely lead to lost logs.
26-
27-
To write logs in an exit handler, create the handler with [`pino.final`](/docs/api.md#pino-final):
28-
29-
```js
30-
process.on('uncaughtException', pino.final(logger, (err, finalLogger) => {
31-
finalLogger.error(err, 'uncaughtException')
32-
process.exit(1)
33-
}))
34-
35-
process.on('unhandledRejection', pino.final(logger, (err, finalLogger) => {
36-
finalLogger.error(err, 'unhandledRejection')
37-
process.exit(1)
38-
}))
39-
```
40-
41-
The `finalLogger` is a special logger instance that will synchronously and reliably
42-
flush every log line. This is important in exit handlers, since no more asynchronous
43-
activity may be scheduled.
15+
* [Exit logging](#exit-logging)
4416

4517
<a id="rotate"></a>
4618
## Log rotation
@@ -299,3 +271,35 @@ log.info({ msg: 'mapped to originalMsg' }, 'a message')
299271
// {"level":30,"time":1596313323106,"pid":63739,"hostname":"foo","msg":"no original message"}
300272
// {"level":30,"time":1596313323107,"pid":63739,"hostname":"foo","msg":"a message","originalMsg":"mapped to originalMsg"}
301273
```
274+
275+
<a id="exit-logging"></a>
276+
## Exit logging (deprecated for Node v14+)
277+
278+
__In pino v7, The following piece of documentation is not needed in Node v14+ and it will
279+
emit a deprecation notice.__
280+
281+
When a Node process crashes from uncaught exception, exits due to a signal,
282+
or exits of it's own accord we may want to write some final logs – particularly
283+
in cases of error.
284+
285+
Writing to a Node.js stream on exit is not necessarily guaranteed, and naively writing
286+
to an asynchronous logger on exit will definitely lead to lost logs.
287+
288+
To write logs in an exit handler, create the handler with [`pino.final`](/docs/api.md#pino-final):
289+
290+
```js
291+
process.on('uncaughtException', pino.final(logger, (err, finalLogger) => {
292+
finalLogger.error(err, 'uncaughtException')
293+
process.exit(1)
294+
}))
295+
296+
process.on('unhandledRejection', pino.final(logger, (err, finalLogger) => {
297+
finalLogger.error(err, 'unhandledRejection')
298+
process.exit(1)
299+
}))
300+
```
301+
302+
The `finalLogger` is a special logger instance that will synchronously and reliably
303+
flush every log line. This is important in exit handlers, since no more asynchronous
304+
activity may be scheduled.
305+

0 commit comments

Comments
 (0)
Please sign in to comment.