log-process-errors
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

downloads last commit license npm node JavaScript Style Guide eslint-config-standard-prettier-fp

Log any process errors:

Usage

const logProcessErrors = require('log-process-errors')

const undoSetup = lopProcessErrors.setup()

When any process errors occur, it will be logged using console.error(). The message will include detailed information about the error.

For warning, console.warn() will be used instead.

You can undo everything by firing the function returned by onProcessError.setup() (called undoSetup in the example above).

Example output

TO BE DONE

Custom handling

You can override the default behavior by passing a custom function to the handle option.

onProcessError.setup({
  handle({ eventName, promiseState, promiseValue, error, message }) {},
})

This can be useful if you want to use your own logger instead of the console.

The function's argument is an object with the following properties:

  • eventName {string}: can be uncaughtException, unhandledRejection, rejectionHandled, multipleResolves or warning
  • error {any} is either:
  • promiseState {string}: whether promise was resolved or rejected. For unhandledRejection, rejectionHandled and multipleResolves.
  • promiseValue {any}: value resolved/rejected by the promise. For unhandledRejection, rejectionHandled and multipleResolves.
  • message {string}: detailed message summing up all of the above.

Exiting on uncaught exceptions

By default, uncaughtException will fire process.exit(1). This is the recommended behavior according to the Node.js documentation.

You can disable this by setting the exitOnExceptions option to false:

onProcessError.setup({ exitOnExceptions: false })

Package Sidebar

Install

npm i log-process-errors@0.2.0

Version

0.2.0

License

Apache-2.0

Unpacked Size

24.7 kB

Total Files

11

Last publish

Collaborators

  • ehmicky