pino-http
pino-http copied to clipboard
`autoLogging.ignore` doesn't receive the response object
Why would autoLogging.ignore not receive a response object. I would like to autolog only errored requests.
You can do it with an error middleware instead of autologging. Here's how I did it:
const logRequest = pinoHttp({
level: 'info',
enabled: true,
autoLogging: false,
});
const app = express();
app.use(logRequest);
app.get('/health', (req, res) => {
res.send('ok');
});
// Only works if it's placed after the routing calls such as app.get()
app.use((err, req, res, next) => {
req.log.error(err)
res.status(500).send('Internal Server Error')
})
app.listen(PORT, () => {
log.info(`server listening for requests on http://localhost:${PORT}`);
});
Would you like to send a Pull Request to address this issue? Remember to add unit tests.