pino-http
pino-http copied to clipboard
quiteReslogger does not appear to work
When I have quiteReslogger, the entire response object is still logged out.
My use-case is that I need certain logging properties from the request/response to be in the root of the log so that they can be consistent with other non-node services.
I would expect that quiteReslogger would limit what is logged about the response, but it seems that it does not do anything - unless I am misunderstanding how the feature is supposed to work.
export const httpLogger = pinoHttp<express.Request, express.Response>({
logger,
autoLogging: {
ignore: (req) => IGNORE_LOG_PATHS.has(req.path),
},
customSuccessMessage: function (req, res) {
if (res.statusCode === 404) {
return `[404] [${req.method}] ${req.url}`;
}
return `${req.method} ${req.url}`;
},
quietReqLogger: true,
quietResLogger: true,
customProps: function (req, res) {
return {
id: req.id,
method: req.method,
url: req.url,
hostname: req.headers.host,
userAgent: req.headers['user-agent'],
statusCode: res.statusCode,
tenantId: req.headers['x-tenant-id'],
userId: req.headers['x-user-id'],
traceId: req.headers['x-b3-traceid'],
spanId: req.headers['x-b3-spanid'],
};
},
});
produces this (using pretty logging locally)
[20:20:03.633] INFO (52057):
reqId: 1
id: 1
method: "GET"
url: "/foo"
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
statusCode: 200
tenantId: "foo"
userId: "foo"
res: {
"statusCode": 200,
"headers": {
"x-powered-by": "Express",
"access-control-allow-origin": "*",
"content-type": "application/json; charset=utf-8",
"content-length": "6516",
"etag": "W/\"1974-3h2XR95mb88G95O2Ua94T2liCwc\""
}
}
responseTime: 85
message: "GET /foo"
Thanks for reporting!
Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.
Here is a reproduction where you can run it and observe the bug https://stackblitz.com/edit/stackblitz-starters-ip4fwd?file=index.js
Same configuration as above, and res is logged out no matter what quietResLogger is set to.
{
"level": 30,
"time": 1728740919701,
"pid": 33,
"hostname": "stackblitzstartersip4fwd-gahw",
"reqId": 7,
"id": 7,
"method": "GET",
"url": "/style.css",
"hostname": "localhost:3010",
"statusCode": 200,
"res": {
"statusCode": 200,
"headers": {
"x-powered-by": "Express",
"accept-ranges": "bytes",
"cache-control": "public, max-age=0",
"last-modified": "Sat, 12 Oct 2024 13:44:53 GMT",
"etag": "W/\"ca-19280f99526\"",
"content-type": "text/css; charset=UTF-8",
"content-length": 202
}
},
"responseTime": 0,
"msg": "GET /style.css"
}
Take a look at https://github.com/pinojs/pino-http/issues/350