1 | # book-raven
|
2 |
|
3 | [raven](https://github.com/getsentry/raven-node) middleware for the [book](https://github.com/defunctzombie/node-book) logging framework
|
4 |
|
5 | ## use
|
6 | ```javascript
|
7 | var log = require('book').default();
|
8 |
|
9 | // add the middleware to your logger
|
10 | log.use(require('book-raven')('your sentry DSN here'));
|
11 |
|
12 | log.warn('hello world');
|
13 | log.info('hello world was logged');
|
14 | ```
|
15 |
|
16 | ## handle errors from sentry
|
17 |
|
18 | Sometimes the messages cannot be sent to sentry. In this case the `on_error` function will be called with the error. If no `on_error` function is specified, the error will simply be thrown and any `uncaughtException` handlers you have installed will catch it (or your app will crash).
|
19 |
|
20 | It is recommended to install some sort of `on_error` handler.
|
21 |
|
22 | ```javascript
|
23 | log.use(require('book-raven')('DSN', {
|
24 | on_error: function(err) {
|
25 | console.error(err);
|
26 | }
|
27 | });
|
28 | ```
|
29 |
|
30 | ## configure levels to send
|
31 |
|
32 | By default, only PANIC, ERROR, and WARN levels are sent to sentry. If you wish to
|
33 | By default, all log entries are sent. If you wish to limit logging to specific levels use the `ignore_levels` option.
|
34 |
|
35 | Below is an example of ignoring all levels above (less critical) than WARN. So PANIC, ERROR, and WARN will be sent to sentry, but INFO, DEBUG, and TRACE will not.
|
36 |
|
37 | ```javascript
|
38 | log.use(require('book-raven')('DSN', {
|
39 | ignore_levels: log.WARN
|
40 | on_error: function(err) {
|
41 | console.error(err);
|
42 | }
|
43 | });
|
44 | ```
|
45 |
|
46 | ## uncaughtException
|
47 |
|
48 | If you use process uncaughtException to handle the error and wish to exit. Make sure to exit after a short timeout. This will give the raven logger a chance to send the http request.
|
49 |
|
50 | ```javascript
|
51 | process.on('uncaughtException', function(err) {
|
52 | log.panic(err);
|
53 | setTimeout(process.exit.bind(process, 1), 1500);
|
54 | })
|
55 | ```
|
56 |
|
57 | ## install
|
58 |
|
59 | ```shell
|
60 | npm install book
|
61 | npm install book-raven
|
62 | ```
|