Comparing version 5.5.0 to 5.6.0
@@ -96,6 +96,4 @@ 'use strict' | ||
if (customProps) { | ||
var customPropBindings = (typeof customProps === 'function') ? customProps(req, res) : customProps | ||
log = log.child(customPropBindings) | ||
} | ||
var customPropBindings = (typeof customProps === 'function') ? customProps(req, res) : customProps | ||
log = log.child(customPropBindings) | ||
req.log = res.log = log | ||
@@ -110,14 +108,13 @@ | ||
url = URL.parse(autoLoggingGetPath(req)) | ||
} else if (req.url) { | ||
} else { | ||
url = URL.parse(req.url) | ||
} | ||
if (url && url.pathname) { | ||
shouldLogSuccess = !autoLoggingIgnorePaths.find(ignorePath => { | ||
if (ignorePath instanceof RegExp) { | ||
return ignorePath.test(url.pathname) | ||
} | ||
return ignorePath === url.pathname | ||
}) | ||
} | ||
shouldLogSuccess = !autoLoggingIgnorePaths.find(ignorePath => { | ||
if (ignorePath instanceof RegExp) { | ||
return ignorePath.test(url.pathname) | ||
} | ||
return ignorePath === url.pathname | ||
}) | ||
} | ||
@@ -146,3 +143,3 @@ | ||
opts.genReqId = undefined | ||
logger = prevLogger.child(opts) | ||
logger = prevLogger.child({}, opts) | ||
opts.logger = prevLogger | ||
@@ -149,0 +146,0 @@ opts.genReqId = prevGenReqId |
{ | ||
"name": "pino-http", | ||
"version": "5.5.0", | ||
"version": "5.6.0", | ||
"description": "High-speed HTTP logger for Node.js", | ||
@@ -8,7 +8,7 @@ "main": "logger.js", | ||
"fast-url-parser": "^1.1.3", | ||
"pino": "^6.0.0", | ||
"pino-std-serializers": "^2.4.0" | ||
"pino": "^6.13.0", | ||
"pino-std-serializers": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"autocannon": "^4.0.0", | ||
"autocannon": "^7.3.0", | ||
"coveralls": "^3.0.0", | ||
@@ -18,9 +18,8 @@ "http-ndjson": "^3.1.0", | ||
"split2": "^3.0.0", | ||
"standard": "^14.0.0", | ||
"tap": "^14.0.0" | ||
"standard": "^16.0.3", | ||
"tap": "^15.0.0" | ||
}, | ||
"scripts": { | ||
"benchmark": "bash ./scripts/benchmark-all", | ||
"test": "standard && tap --no-cov test.js", | ||
"ci": "standard && tap --cov test.js", | ||
"test": "standard && tap test.js", | ||
"fix": "standard --fix" | ||
@@ -27,0 +26,0 @@ }, |
@@ -96,3 +96,3 @@ # pino-http [![Build Status](https://img.shields.io/github/workflow/status/pinojs/pino-http/CI)](https://github.com/pinojs/pino-http/actions) | ||
* `logger`: `pino-http` can reuse a pino instance if passed with the `logger` property | ||
* `logger`: parent pino instance for a child logger instance, which will be used by `pino-http`. To refer to this child instance, use [pinoHttp.logger](#pinohttplogger-plogger) | ||
* `genReqId`: you can pass a function which gets used to generate a request id. The first argument is the request itself. As fallback `pino-http` is just using an integer. This default might not be the desired behavior if you're running multiple instances of the app | ||
@@ -110,2 +110,3 @@ * `useLevel`: the logger level `pino-http` is using to log out the response. default: `info` | ||
* `customProps`: set to a `function (req,res) => { /* returns on object */ }` or `{ /* returns on object */ }` This function will be invoked for each request with `req` and `res` where we could pass additional properties that needs to be logged outside the `req`. | ||
`stream`: the destination stream. Could be passed in as an option too. | ||
@@ -192,2 +193,14 @@ | ||
##### PinoHttp.logger (P.Logger) | ||
The `pinoHttp` instance has a property `logger`, which references to an actual logger instance, used | ||
by pinoHttp. This instance will be a child of an instance, passed as `opts.logger`, or a fresh one, | ||
if no `opts.logger` is passed. It can be used, for example, for doing most of the things, possible | ||
to do with any `pino` instance, for example changing logging level in runtime, like so: | ||
```js | ||
var pinoHttp = require('pinoHttp')(); | ||
pinoHttp.logger.level = 'silent'; | ||
``` | ||
##### pinoHttp.startTime (Symbol) | ||
@@ -194,0 +207,0 @@ |
35
test.js
@@ -12,5 +12,5 @@ 'use strict' | ||
function setup (t, logger, cb, handler) { | ||
function setup (t, logger, cb, handler, next) { | ||
var server = http.createServer(handler || function (req, res) { | ||
logger(req, res) | ||
logger(req, res, next) | ||
if (req.url === '/') { | ||
@@ -31,3 +31,3 @@ res.end('hello world') | ||
}) | ||
t.tearDown(function (cb) { | ||
t.teardown(function (cb) { | ||
server.close(cb) | ||
@@ -161,3 +161,3 @@ }) | ||
dest.on('data', function (line) { | ||
t.notEqual(line.req.id, lastId) | ||
t.not(line.req.id, lastId) | ||
lastId = line.req.id | ||
@@ -507,3 +507,3 @@ t.ok(line.req.id, 'req.id is defined') | ||
dest.on('data', function (obj) { | ||
t.is(Object.keys(obj.req).length, 6) | ||
t.equal(Object.keys(obj.req).length, 6) | ||
}) | ||
@@ -595,3 +595,3 @@ }) | ||
res: function (res) { | ||
t.is(Object.prototype.propertyIsEnumerable.call(res, 'raw'), false) | ||
t.equal(Object.prototype.propertyIsEnumerable.call(res, 'raw'), false) | ||
return res | ||
@@ -660,3 +660,3 @@ } | ||
req: function (req) { | ||
t.is(typeof req.id === 'function', false) | ||
t.equal(typeof req.id === 'function', false) | ||
return req | ||
@@ -714,3 +714,3 @@ } | ||
dest.on('data', function (line) { | ||
t.contains(line.msg, customErrorMessage) | ||
t.equal(line.msg.indexOf(customErrorMessage), 0) | ||
t.end() | ||
@@ -860,1 +860,20 @@ }) | ||
}) | ||
test('auto logging and next callback', function (t) { | ||
t.plan(3) | ||
var dest = split(JSON.parse) | ||
var logger = pinoHttp({ autoLogging: true }, dest) | ||
setup(t, logger, function (err, server) { | ||
t.error(err) | ||
doGet(server, null, function () { | ||
var line = dest.read() | ||
t.equal(line.msg, 'request completed') | ||
}) | ||
}, function (req, res) { | ||
logger(req, res, function () { | ||
t.pass('called') | ||
res.end('hello world') | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42815
15
953
373
+ Addedpino-std-serializers@4.0.0(transitive)
- Removedpino-std-serializers@2.5.0(transitive)
Updatedpino@^6.13.0
Updatedpino-std-serializers@^4.0.0