Skip to content

Commit 8615d7d

Browse files
alexk-blackopsalexk-blackops
authored andcommitted
readme fixes
1 parent ad6b8b3 commit 8615d7d

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ The following options could be passed. 'apiKey' is the only one that required:
3232
#### Using with Winston
3333

3434
```bash
35-
$ npm install stackify-logger
35+
$ npm install winston-stackify
3636
```
3737

3838
If you are already using Winston you should add the stackify transport module to your instance of Winston:
3939
```js
40-
require('winston-stackify');
40+
require('winston-stackify').Stackify;
4141
winston.add(winston.transports.Stackify(options));
4242
```
4343

@@ -72,42 +72,44 @@ stackify.log('error', {error : new Error()});
7272
When logging an error message you could pass an Error object in metadata like in the last case so the exception details would be available.
7373

7474
#### Exception handling
75-
Supported frameworks
76-
Express (ver 4.x) and all express-based frameworks only (e.g. SailsJS, Connect, LocomotiveJS) will be supported. This means all of the frameworks that support the format of the middleware functions used in Express.JS.
77-
function (req, res, next) {
78-
//some code
79-
next();
80-
}
75+
By executing stackify.start() you set handler for uncaught exceptions.
76+
Be sure to run it before any methods that set exception handlers.
8177

8278
##### Using with pure NodeJS app
83-
If you are not using any of the frameworks and all requests are handled inside native createServer method you should run stackify.exceptionHandler() first line inside of this method :
79+
If you are not using any of the frameworks and all requests are handled inside native `createServer()` method and you want to get web details of exception to be sent with it you should run stackify.exceptionHandler(req) first line inside of this method :
8480

8581
```js
8682
var http = require('http');
8783
var stackify = require('stackify-logger');
8884
http.createServer(function (req, res) {
89-
stackify.stats(req, res);
85+
stackify.exceptionHandler(req);
9086
res.setHeader('content-type', 'text/plain');
9187
res.end('hello');
9288
});
9389
});
9490
```
91+
where req is request object, instance of `http.IncomingMessage`
9592

9693
You can use it also with any framework that doesn’t modify native createServer method.
9794

9895

9996
##### Using with Express
100-
It acts as middleware when running on express-based apps. Since middleware are execute serially, their order of inclusion is important.
101-
102-
You can activate it with the app.use() command in the appropriate place of your code, e.g.:
97+
Global handler doesn't work inside Express route methods.
98+
You should use error-handling middleware function `stackify.expressExceptionHandler`. Since middleware is executed serially, it's order of inclusion is important. Be sure to add it before any other error-handling middleware.
10399

104100
```js
105101
var express = require('express');
106102
var app = express();
107-
app.use(stackify.expressExceptionHandler());
103+
104+
/*
105+
*** block of route handlers ***
106+
*** *** **** **** **** **** ***
107+
*/
108+
109+
app.use(stackify.expressExceptionHandler);
108110
```
109111

110-
To handle exceptions correctly put this right after all route handlers and before all the other error middleware.
112+
To handle exceptions correctly put this right after all route handlers.
111113

112114
## License
113115

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
// start sending logs
77
start: function (options) {
88
api.methods.identifyApp(options);
9-
exception.exceptionHandler(options.exitOnError);
9+
exception.exceptionHandler(null, options.exitOnError);
1010
},
1111

1212
log: logger.methods.log,

lib/exception.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
// Pure Node apps exception catching
1010
exceptionHandler : function exceptionHandler(req, exit) {
1111
var self = this;
12+
CONFIG.EXIT_ON_ERROR = CONFIG.EXIT_ON_ERROR || exit;
1213
return (function () {
1314
var body = '';
1415
if (req) {
@@ -25,7 +26,7 @@ module.exports = {
2526
if (!self.excCaught) {
2627
self.excCaught = true;
2728
logger.methods.sendException(err, req, function () {
28-
if (exit === true) {
29+
if (CONFIG.EXIT_ON_ERROR === true) {
2930
process.exit(1);
3031
}
3132
});
@@ -34,11 +35,9 @@ module.exports = {
3435
}());
3536
},
3637
// Express error handling middleware
37-
expressExceptionHandler : function expressExceptionHandler(options) {
38-
var self = this;
39-
return function expressExceptionHandler(err, req, res, next) {
38+
expressExceptionHandler : function expressExceptionHandler(err, req, res, next) {
4039
var cb = function () {
41-
if (options.exitOnError === true) {
40+
if (CONFIG.EXIT_ON_ERROR === true) {
4241
process.exit(1);
4342
} else {
4443
next(err);
@@ -49,8 +48,8 @@ module.exports = {
4948
return next();
5049
}
5150

52-
if (!self.excCaught) {
53-
self.excCaught = true;
51+
if (!this.excCaught) {
52+
this.excCaught = true;
5453
logger.methods.sendException(err, req, cb);
5554
}
5655

0 commit comments

Comments
 (0)