Package Exports
- log-process-errors
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (log-process-errors) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Show some ❤️ to process errors in Node.js.
By default Node.js prints
uncaughtException,
warning and
mishandled promises
(unhandledRejection,
rejectionHandled,
multipleResolves)
on the console which is very useful. Unfortunately those process errors:
- show neither stack traces nor promise values for
warning,rejectionHandledandmultipleResolvesmaking it hard to debug. - are inconvenient to log to an external service.
- cannot be conditionally skipped.
- are printed each time an error is repeated (except for
warning). - are not human-friendly.
log-process-errors fixes all those issues.
Without log-process-errors:

With log-process-errors:

Install
Production code (e.g. a web server) can install this either as a production or development dependency:
npm install log-process-errorsHowever libraries should install this as a development dependency:
npm install -D log-process-errorsThis is because logging is modified globally and libraries users might not expect this side-effect. Also this might lead to conflicts between libraries.
Usage
There are two ways to load this library. The first is to use the
node -r CLI flag:
node -r log-process-errors/register ...The second is:
const logProcessErrors = require('log-process-errors')
logProcessErrors(options)logProcessErrors() should be called as early as possible in the code.
Options
options is an optional object with the following properties:
log{function}: override how events are logged. Default: useconsole.warn(),console.error(), etc.level{object}: which log level to use. Default:{ warning: 'warn', multipleResolves: 'info', default: 'error' }.message{function}: override the default message generation.colors{boolean}: colorize the default message. Default:true.exitOn{string[]}: which events should triggerprocess.exit(1). Default:['uncaughtException'].
Please see the options full documentation.
Full example:
logProcessErrors({
log(message, level, info) {
winstonLogger[level](message)
},
level: { multipleResolves: 'debug' },
message(info) {},
colors: false,
exitOn: ['uncaughtException', 'unhandledRejection'],
})Restoring default behavior
Node.js default behavior can be restored by firing the function returned by
logProcessErrors().
const restore = logProcessErrors(options)
restore()