Description
Node.js prints process errors (`uncaughtException`, `warning`, `unhandledRejection`, `rejectionHandled`) on the console which is very useful. Unfortunately those errors:
- do not show stack traces for `warning` and `rejectionHandled` making them hard to debug.
- do not include `multipleResolves` errors (when a promise is resolved/rejected twice).
- are inconvenient to log to an external service.
- are hard to test.
- 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.
log-process-errors alternatives and similar modules
Based on the "Logging" category.
Alternatively, view log-process-errors alternatives based on common mentions on social networks and blogs.
-
Bunyan
a simple and fast JSON logging module for node.js services -
tracer for node.js
A powerful and customizable logging library for node.js -
storyboard
End-to-end, hierarchical, real-time, colorful logs and stories -
console-log-level
The most simple logger imaginable -
What projects belong to here?
Better logging messages for Nodejs developers -
Consono
The most correct, informative, appealing and configurable variable inspector for JavaScript -
oddlog
A high-performance payload focused logging library for node.js
Appwrite - The open-source backend cloud platform
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of log-process-errors or a related project?
README
Show some ❤️ to Node.js process errors.
Node.js prints process errors
(uncaughtException
,
warning
,
unhandledRejection
,
rejectionHandled
)
on the console which is very useful. Unfortunately those errors:
- do not show stack traces for
warning
andrejectionHandled
making them hard to debug. - do not include
multipleResolves
errors (when a promise is resolved/rejected twice). - are inconvenient to [log to an external service](docs/API.md#log).
- are hard to [test](docs/API.md#testing).
- 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
:
[Screenshot before](docs/before.png)
With log-process-errors
:
[Screenshot after](docs/after.png)
Use cases
- Proper logging of process errors in production.
- Debugging of process errors in development.
- Automated testing of process errors.
Demo
You can try this library:
- either directly in your browser.
- or by executing the [
examples
files](examples/README.md) in a terminal.
Install
Production code (e.g. a server) can install this either as a production or development dependency:
npm install log-process-errors
However, libraries should install this as a development dependency:
npm install -D log-process-errors
This 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/build/register ...
The second is:
const logProcessErrors = require('log-process-errors')
logProcessErrors(options)
logProcessErrors()
should be called as early as possible in the code, before
other require
/import
statements.
Options
options
is an optional object with the following properties.
log
Type: function(error, level, originalError)
Customizes how process errors are logged.\ [Full documentation](docs/API.md#log).
level
Type: object
\
Default: { warning: 'warn', multipleResolves: 'info', default: 'error' }
Which log level to use.\ [Full documentation](docs/API.md#level).
exitOn
Type: string[]
\
Default: ['uncaughtException']
Which process errors should trigger process.exit(1)
.\
[Full documentation](docs/API.md#exiton).
testing
Type: string
\
Value: 'ava'
, 'mocha'
, 'jasmine'
, 'tape'
or 'node-tap'
\
Default: undefined
When running tests, makes them fail if there are any process errors.\ [Full documentation](docs/API.md#testing).
colors
Type: boolean
\
Default: true
if the output is a terminal.
Colorizes messages.\ [Full documentation](docs/API.md#colors).
Support
If you found a bug or would like a new feature, don't hesitate to [submit an issue on GitHub](../../issues).
For other questions, feel free to chat with us on Gitter.
Everyone is welcome regardless of personal background. We enforce a [Code of conduct](CODE_OF_CONDUCT.md) in order to promote a positive and inclusive environment.
Contributing
This project was made with ❤️. The simplest way to give back is by starring and sharing it online.
If the documentation is unclear or has a typo, please click on the page's Edit
button (pencil icon) and suggest a correction.
If you would like to help us fix a bug or add a new feature, please check our [guidelines](CONTRIBUTING.md). Pull requests are welcome!
Thanks go to our wonderful contributors:
<!-- ALL-CONTRIBUTORS-LIST:START --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> ehmicky💻 🎨 🤔 📖 Steven Vachon💬 Hongarc📖 💻 Andy Brenneke🐛
<!-- markdownlint-enable --> <!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->