|
1 | 1 | # Help
|
2 | 2 |
|
3 |
| -* [Exit logging](#exit-logging) |
4 | 3 | * [Log rotation](#rotate)
|
5 | 4 | * [Reopening log files](#reopening)
|
6 | 5 | * [Saving to multiple files](#multiple)
|
|
13 | 12 | * [Unicode and Windows terminal](#windows)
|
14 | 13 | * [Mapping Pino Log Levels to Google Cloud Logging (Stackdriver) Serverity Levels](#stackdriver)
|
15 | 14 | * [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) |
44 | 16 |
|
45 | 17 | <a id="rotate"></a>
|
46 | 18 | ## Log rotation
|
@@ -299,3 +271,35 @@ log.info({ msg: 'mapped to originalMsg' }, 'a message')
|
299 | 271 | // {"level":30,"time":1596313323106,"pid":63739,"hostname":"foo","msg":"no original message"}
|
300 | 272 | // {"level":30,"time":1596313323107,"pid":63739,"hostname":"foo","msg":"a message","originalMsg":"mapped to originalMsg"}
|
301 | 273 | ```
|
| 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