Comparing version 8.1.1 to 8.2.0
@@ -139,3 +139,3 @@ 'use strict' | ||
req.id = genReqId(req) | ||
req.id = genReqId(req, res) | ||
@@ -159,3 +159,3 @@ const log = quietReqLogger ? logger.child({ [requestIdKey]: req.id }) : logger | ||
if (autoLoggingIgnore !== null && shouldLogSuccess === true) { | ||
const isIgnored = autoLoggingIgnore !== null && autoLoggingIgnore(req) | ||
const isIgnored = autoLoggingIgnore(req) | ||
shouldLogSuccess = !isIgnored | ||
@@ -214,3 +214,3 @@ } | ||
let nextReqId = 0 | ||
return function genReqId (req) { | ||
return function genReqId (req, res) { | ||
return req.id || (nextReqId = (nextReqId + 1) & maxInt) | ||
@@ -217,0 +217,0 @@ } |
{ | ||
"name": "pino-http", | ||
"version": "8.1.1", | ||
"version": "8.2.0", | ||
"description": "High-speed HTTP logger for Node.js", | ||
@@ -26,3 +26,3 @@ "main": "logger.js", | ||
"ts-node": "^10.3.0", | ||
"tsd": "^0.21.0", | ||
"tsd": "^0.22.0", | ||
"typescript": "^4.4.4" | ||
@@ -29,0 +29,0 @@ }, |
@@ -125,2 +125,3 @@ # pino-http [![Build Status](https://img.shields.io/github/workflow/status/pinojs/pino-http/CI)](https://github.com/pinojs/pino-http/actions) | ||
const server = http.createServer(handle) | ||
const { randomUUID } = require('node:crypto') | ||
const pino = require('pino') | ||
@@ -132,3 +133,10 @@ const logger = require('pino-http')({ | ||
// Define a custom request id function | ||
genReqId: function (req) { return req.id }, | ||
genReqId: function (req, res) { | ||
if (req.id) return req.id | ||
let id = req.get('X-Request-Id') | ||
if (id) return id | ||
id = randomUUID() | ||
res.header('X-Request-Id', id) | ||
return id | ||
}, | ||
@@ -135,0 +143,0 @@ // Define custom serializers |
@@ -289,7 +289,8 @@ 'use strict' | ||
test('uses a custom genReqId function', function (t) { | ||
t.plan(4) | ||
t.plan(5) | ||
const dest = split(JSON.parse) | ||
let idToTest | ||
function genReqId (req) { | ||
function genReqId (req, res) { | ||
t.ok(res, 'res is defined') | ||
t.ok(req.url, 'The first argument must be the request parameter') | ||
@@ -540,3 +541,4 @@ idToTest = (Date.now() + Math.random()).toString(32) | ||
let idToTest | ||
function genReqId (req) { | ||
function genReqId (req, res) { | ||
t.ok(res, 'res is defined') | ||
t.ok(req.url, 'The first argument must be the request parameter') | ||
@@ -543,0 +545,0 @@ idToTest = (Date.now() + Math.random()).toString(32) |
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
71985
1677
459