Skip to content

Commit aff0ef7

Browse files
committed
Upgrade README.md
1 parent f9bf840 commit aff0ef7

File tree

1 file changed

+48
-39
lines changed

1 file changed

+48
-39
lines changed

README.md

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ logProcessErrors(options)
3535

3636
By default events will be logged to the console (e.g. `console.error()`).
3737

38-
This behavior can be overriden with the `log` option. For example to log events
38+
This behavior can be overridden with the `log` option. For example to log events
3939
with [Winston](https://github.com/winstonjs/winston) instead:
4040

4141
<!-- eslint-disable no-empty-function, no-unused-vars, node/no-missing-require,
@@ -55,36 +55,19 @@ The function's arguments are:
5555
customized with the [`getMessage` option](#log-message).
5656
- `level` `{string}`: log level. Can be customized with the
5757
[`getLevel` option](#log-level).
58-
- `info` `{object}`:
59-
- information about the event
60-
- has the following properties:
61-
- `eventName` `{string}`: can be `uncaughtException`, `unhandledRejection`,
62-
`rejectionHandled`, `multipleResolves` or `warning`
63-
- `error` `{any}`:
64-
- either the value thrown by `uncaughtException`
65-
- or the error emitted by `warning`.
66-
[`error.code` and `error.detail`](https://nodejs.org/api/process.html#process_event_warning)
67-
might be defined.
68-
- it is usually an `Error` instance but could technically be anything
69-
- `promiseState` `{string}`: whether the promise was `resolved` or
70-
`rejected`
71-
- `promiseValue` `{any}`: value resolved/rejected by the promise
72-
- `secondPromiseState`, `secondPromiseValue`: like `promiseState` and
73-
`promiseValue` but for the second time the promise was resolved/rejected
74-
- whether the properties above are defined or not depends on the event name:
75-
- `eventName`: always present
76-
- `error`: only on `uncaughtException` and `warning`
77-
- `promiseState`, `promiseValue`: only on `unhandledRejection`,
78-
`rejectionHandled` and `multipleResolves`
79-
- `secondPromiseState`, `secondPromiseValue`: only on `multipleResolves`
58+
- `info` `{object}`: [event information](#event-info)
59+
60+
If logging is asynchronous, the function should return a promise (or use
61+
`async`/`await`). This is not necessary if logging is using streams (like
62+
Winston).
8063

8164
# Log level
8265

8366
By default the log level will be `warn` for `warning` events and `error` for
8467
the other events.
8568

86-
This can be overriden by using the `getLevel` option. It should be a function
87-
function using [`info` as argument](#custom-logging) and returning a string
69+
This can be overridden by using the `getLevel` option. It should be a function
70+
function using [`info` as argument](#event-info) and returning a string
8871
among `error`, `warn`, `info` or `debug`.
8972

9073
<!-- eslint-disable no-empty-function, no-unused-vars, node/no-missing-require,
@@ -107,18 +90,14 @@ The message will be colorized unless either:
10790
- the output [does not support colors](https://github.com/chalk/supports-color)
10891
- the option `colors` is set to `false`
10992

110-
The message generation can be overriden by using the `getMessage` option. It
111-
should be a function using [`info` as argument](#custom-logging) and returning
112-
a string. The `info` argument also has the following properties:
113-
114-
- `level` `{string}`
115-
- `colors` `{object}`: [Chalk instance](https://github.com/chalk/chalk#api)
116-
to colorize strings (disabled if the option `colors` is `false`)
93+
The message generation can be overridden by using the `getMessage` option. It
94+
should be a function using [`info` as argument](#event-info) and returning
95+
a string.
11796

11897
# Skipping events
11998

12099
Events can be skipped with the `skipEvent` option. It should be a function
121-
using [`info` as argument](#custom-logging) and returning `true` or `false`.
100+
using [`info` as argument](#event-info) and returning `true` or `false`.
122101

123102
For example to skip `warning` events:
124103

@@ -133,16 +112,46 @@ logProcessErrors({
133112
})
134113
```
135114

115+
# Event information
116+
117+
The options `log`, `getLevel`, `getMessage` and `skipEvent` all receive as
118+
argument an `info` object with information about the event. It has the following
119+
properties:
120+
121+
- `eventName` `{string}`: can be `uncaughtException`, `unhandledRejection`,
122+
`rejectionHandled`, `multipleResolves` or `warning`
123+
- `error` `{any}`:
124+
- either the value thrown by `uncaughtException`
125+
- or the error emitted by `warning`.
126+
[`error.code` and `error.detail`](https://nodejs.org/api/process.html#process_event_warning)
127+
might be defined.
128+
- it is usually an `Error` instance but could technically be anything
129+
- `promiseState` `{string}`: whether the promise was `resolved` or
130+
`rejected`
131+
- `promiseValue` `{any}`: value resolved/rejected by the promise
132+
- `secondPromiseState`, `secondPromiseValue`: like `promiseState` and
133+
`promiseValue` but for the second time the promise was resolved/rejected
134+
135+
Whether the properties above are defined or not depends on the event name:
136+
137+
- `eventName`: always present
138+
- `error`: only on `uncaughtException` and `warning`
139+
- `promiseState`, `promiseValue`: only on `unhandledRejection`,
140+
`rejectionHandled` and `multipleResolves`
141+
- `secondPromiseState`, `secondPromiseValue`: only on `multipleResolves`
142+
143+
The following properties are also defined with the `getMessage` option:
144+
145+
- `level` `{string}`
146+
- `colors` `{object}`: [Chalk instance](https://github.com/chalk/chalk#api)
147+
to colorize strings (disabled if the option `colors` is `false`)
148+
136149
# Uncaught exceptions
137150

138-
`uncaughtException` events will fire `process.exit(1)`. This is the recommended
139-
behavior according to the
151+
`uncaughtException` events will fire `process.exit(1)` after being successfully
152+
logged. Exiting is the default behavior and is recommended by the
140153
[Node.js documentation](https://nodejs.org/api/process.html#process_warning_using_uncaughtexception_correctly).
141154

142-
`process.exit(1)` will only be fired after the `uncaughtException` event has
143-
been logged. If an custom `log` option is used and it is asynchronous, the
144-
function should return a promise (or use `async`/`await`).
145-
146155
# Stop logging
147156

148157
Logging can be stopped by firing the function returned by `logProcessErrors()`

0 commit comments

Comments
 (0)