@@ -32,7 +32,7 @@ Without `log-process-errors`:
3232
3333![ Screenshot after] ( docs/after.png )
3434
35- # Installation
35+ # Install
3636
3737Production code (e.g. a web server) can install this either as a production or
3838development dependency:
@@ -70,161 +70,41 @@ logProcessErrors(options)
7070
7171` logProcessErrors() ` should be called as early as possible in the code.
7272
73- ` options ` is an optional object with the following properties:
73+ # Options
7474
75- - [ ` log ` ` {function} ` ] ( #custom-logging )
76- - [ ` level ` ` {object} ` ] ( #log-level )
77- - [ ` message ` ` {function} ` ] ( #log-message )
78- - [ ` colors ` ` {boolean} ` ] ( #log-message )
79- - [ ` exitOn ` ` {string[]} ` ] ( #process-exit )
75+ ` options ` is an optional object with the following properties:
8076
81- # Custom logging
77+ - [ ` log ` ` {function} ` ] ( #custom-logging ) : override how events are logged.
78+ Default: use ` console.warn() ` , ` console.error() ` , etc.
79+ - [ ` level ` ` {object} ` ] ( #log-level ) : which log level to use. Default:
80+ ` { warning: 'warn', multipleResolves: 'info', default: 'error' } ` .
81+ - [ ` message ` ` {function} ` ] ( #log-message ) : override the default message
82+ generation.
83+ - [ ` colors ` ` {boolean} ` ] ( #log-message ) : colorize the default message. Default:
84+ ` true ` .
85+ - [ ` exitOn ` ` {string[]} ` ] ( #process-exit ) : which events should trigger
86+ ` process.exit(1) ` . Default: ` ['uncaughtException'] ` .
8287
83- By default events will be logged to the console using ` console.error() ` ,
84- ` console.warn() ` , etc.
88+ Please see the [ options full documentation] ( options.md ) .
8589
86- This behavior can be overridden with the ` log ` option. For example to log events
87- with [ Winston] ( https://github.com/winstonjs/winston ) instead:
90+ Example:
8891
8992``` js
9093logProcessErrors ({
9194 log (message , level , info ) {
9295 winstonLogger[level](message)
9396 },
94- })
95- ```
96-
97- The function's arguments are [ ` message ` ] ( #log-message ) (string),
98- [ ` level ` ] ( #log-level ) (string) and [ ` info ` ] ( #event-information ) (object).
99-
100- If logging is asynchronous, the function should return a promise (or use
101- ` async ` /` await ` ). This is not necessary if logging is using streams (like
102- [ Winston] ( https://github.com/winstonjs/winston ) ).
10397
104- Duplicate events are only logged once (whether the ` log ` option is defined or
105- not).
98+ level: { multiResolves: ' debug' },
10699
107- # Log level
100+ message ( info ) {},
108101
109- The default log level is ` warn ` for
110- [ ` warning ` ] ( https://nodejs.org/api/process.html#process_event_warning ) ,
111- ` info ` for
112- [ ` multipleResolves ` ] ( https://nodejs.org/api/process.html#process_event_multipleresolves )
113- and ` error ` for the other events.
102+ colors: false ,
114103
115- This can be overridden by using the ` level ` option. It should be an
116- object whose:
117-
118- - keys are the event names among ` "default" ` ,
119- [ ` "uncaughtException" ` ] ( https://nodejs.org/api/process.html#process_event_uncaughtexception ) ,
120- [ ` "warning" ` ] ( https://nodejs.org/api/process.html#process_event_warning ) ,
121- [ ` "unhandledRejection" ` ] ( https://nodejs.org/api/process.html#process_event_unhandledrejection ) ,
122- [ ` "rejectionHandled" ` ] ( https://nodejs.org/api/process.html#process_event_rejectionhandled )
123- or
124- [ ` "multipleResolves" ` ] ( https://nodejs.org/api/process.html#process_event_multipleresolves ) .
125- - values are the log level which can be:
126- - a string among ` "debug" ` , ` "info" ` , ` "warn" ` , ` "error" ` or ` "silent" ` .
127- - ` undefined ` to use the default value.
128- - a function using [ ` info ` as argument] ( #event-information ) and
129- returning a string or ` undefined ` (as above).
130-
131- ``` js
132- logProcessErrors ({
133- // Use `debug` log level for `multipleResolves` instead of `info`
134- level: { multipleResolves: ' debug' },
104+ exitOn: [' uncaughtException' , ' unhandledRejection' ],
135105})
136106```
137107
138- ``` js
139- logProcessErrors ({
140- // Skip some logs based on a condition
141- level: {
142- default () {
143- if (shouldSkip ()) {
144- return ' silent'
145- }
146- },
147- },
148- })
149- ```
150-
151- # Log message
152-
153- A nice-looking and descriptive log message is generated by default.
154-
155- The message will be colorized unless the option ` colors ` is set to ` false ` .
156-
157- The message generation can be overridden by using the ` message ` option. It
158- should be a function using [ ` info ` as argument] ( #event-information ) and
159- returning a string.
160-
161- # Event information
162-
163- The [ ` log ` ] ( #custom-logging ) , [ ` level ` ] ( #log-level ) and
164- [ ` message ` ] ( #log-message ) options all receive as argument an ` info ` object.
165-
166- ## ` info.eventName `
167-
168- Can be
169- [ ` "uncaughtException" ` ] ( https://nodejs.org/api/process.html#process_event_uncaughtexception ) ,
170- [ ` "unhandledRejection" ` ] ( https://nodejs.org/api/process.html#process_event_unhandledrejection ) ,
171- [ ` "rejectionHandled" ` ] ( https://nodejs.org/api/process.html#process_event_rejectionhandled ) ,
172- [ ` "multipleResolves" ` ] ( https://nodejs.org/api/process.html#process_event_multipleresolves )
173- or
174- [ ` "warning" ` ] ( https://nodejs.org/api/process.html#process_event_warning ) .
175-
176- ## ` info.value `
177-
178- Value:
179-
180- - thrown by
181- [ ` uncaughtException ` ] ( https://nodejs.org/api/process.html#process_event_uncaughtexception ) .
182- - resolved/rejected by the promise with
183- [ ` unhandledRejection ` ] ( https://nodejs.org/api/process.html#process_event_unhandledrejection ) ,
184- [ ` rejectionHandled ` ] ( https://nodejs.org/api/process.html#process_event_rejectionhandled )
185- and
186- [ ` multipleResolves ` ] ( https://nodejs.org/api/process.html#process_event_multipleresolves ) .
187- - emitted by
188- [ ` warning ` ] ( https://nodejs.org/api/process.html#process_event_warning ) .
189-
190- It is usually an ` Error ` instance but could be anything.
191-
192- ## ` info.rejected `
193-
194- Boolean indicating whether the promise was initially resolved or rejected. Only
195- defined with
196- [ ` multipleResolves ` ] ( https://nodejs.org/api/process.html#process_event_multipleresolves ) .
197-
198- ## ` info.nextValue ` , ` info.nextRejected `
199-
200- Like [ ` value ` ] ( #infovalue ) and [ ` rejected ` ] ( #inforejected ) but for
201- the second time the promise was resolved/rejected. Only defined with
202- [ ` multipleResolves ` ] ( https://nodejs.org/api/process.html#process_event_multipleresolves ) .
203-
204- ## ` info.level `
205-
206- [ Log level] ( #log-level ) . Only defined with the [ ` message ` option] ( #log-message ) .
207-
208- ## ` info.colors `
209-
210- [ Chalk instance] ( https://github.com/chalk/chalk#api ) to colorize strings.
211- Only defined with the [ ` message ` option] ( #log-message ) . Disabled if the
212- [ ` colors ` option] ( #log-message ) is ` false ` .
213-
214- # Process exit
215-
216- The ` exitOn ` option specifies which event should trigger ` process.exit(1) ` :
217-
218- - the default value is ` ["uncaughtException"] ` . This is the
219- [ default behavior] ( https://nodejs.org/api/process.html#process_warning_using_uncaughtexception_correctly )
220- of Node.js.
221- - we recommend using ` ["uncaughtException", "unhandledRejection"] `
222- instead since this will be the [ future default behavior of Node.js] ( https://nodejs.org/dist/latest-v8.x/docs/api/deprecations.html#deprecations_dep0018_unhandled_promise_rejections ) .
223- - to prevent any ` process.exit(1) ` use ` [] ` . Recommended if your process is
224- long-running and does not automatically restart on exit.
225-
226- ` process.exit(1) ` will only be fired after successfully logging the event.
227-
228108# Restoring default behavior
229109
230110Node.js default behavior can be restored by firing the function returned by
0 commit comments