Comparing version 3.0.3 to 3.0.4
@@ -60,7 +60,31 @@ 'use strict'; | ||
var customized = { | ||
err: serialErr, | ||
// modified from bunyan for express | ||
req: function (req) { | ||
if (!req || !req.connection) | ||
return req; | ||
return { | ||
method: req.method, | ||
url: req.originalUrl || req.url, | ||
headers: req.headers, | ||
remoteAddress: req.connection.remoteAddress, | ||
remotePort: req.connection.remotePort | ||
}; | ||
// Trailers: Skipping for speed. If you need trailers in your app, then | ||
// make a custom serializer. | ||
//if (Object.keys(trailers).length > 0) { | ||
// obj.trailers = req.trailers; | ||
//} | ||
} | ||
}; | ||
var serializers = Object.assign(bunyan.stdSerializers, customized); | ||
return bunyan.createLogger({ | ||
name, | ||
streams, | ||
serializers: Object.assign(bunyan.stdSerializers, {err: serialErr}) | ||
serializers | ||
}); | ||
}; |
@@ -26,3 +26,4 @@ 'use strict'; | ||
if (!err || !err.stack) | ||
return err; | ||
return Object.assign({}, err); | ||
var obj = { | ||
@@ -52,4 +53,9 @@ message: err.message, | ||
let original = stringify(err.original); | ||
let original = null; | ||
try { | ||
original = stringify(err.original); | ||
} catch (er) {} | ||
try { | ||
obj.original = JSON.parse(original); | ||
@@ -56,0 +62,0 @@ } catch (er) { |
{ | ||
"name": "bunlogger", | ||
"description": "bunyan logger, bunyan express middleware, pretty print err for development", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"author": "Ben P.P. Tung", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -14,5 +14,5 @@ bunlogger | ||
======== | ||
1. `app.use(logger.connect())` will populate the `req.log`, which is actually a child of the bunyan logger, simply `req.log.info('...')` will share the same `cor_id` in the `access log` and `error log`. | ||
1. `app.use(logger.connect())` will populate the `req.log`, which is actually a child of the bunyan logger, simply `req.log.info('...')` will share the same `cor_id` in the `access log` and `error log`. cor_id is exposed on `req.cor_id`; | ||
2. logging `req.log.fatal()`, `req.log.error()`, `req.log.warn()` into error log file. If error is sent to `next(err)` and `req.log[error_level]` not got called, middleware `app.use(logger.onError())` will log this error by `error.status` automatically. err.status == 4xx is warn level, err.status == 5xx is error level. | ||
2. logging `req.log.fatal()`, `req.log.error()` into error log file. If error is sent to `next(err)` and `req.log['fatal|error']` not got called, middleware `app.use(logger.onError())` will log this error by `error.status` automatically. err.status == 4xx is warn level, err.status == 5xx is error level. | ||
@@ -25,2 +25,3 @@ 3. `elapsed` show the time spent in this `req`. | ||
Quick Start | ||
@@ -54,2 +55,4 @@ ========== | ||
Finally, render `req.cor_id` in the final error handler, so the customer can contact you with `cor_id` for help. | ||
### Create logger | ||
@@ -73,2 +76,4 @@ | ||
A handy tool to replace console.error(err). | ||
``` | ||
@@ -75,0 +80,0 @@ const printErr = require('bunlogger').printErr; |
65510
229
104