Customize structured log objects with hooks
masterYou can augment the base loggable object for received, successful, or errored requests using object hooks. These hooks receive the current loggable object (val) and allow you to merge in custom event labels or metadata.
const logger = require('pino-http')({
customReceivedObject: (req, res, val) => {
return {
...val,
category: 'ApplicationEvent',
eventCode: 'REQUEST_RECEIVED'
};
},
customSuccessObject: (req, res, val) => {
return {
...val,
category: 'ApplicationEvent',
eventCode: res.statusCode < 300 ? 'REQUEST_PROCESSED' : 'REQUEST_FAILED'
};
},
customErrorObject: (req, res, error, val) => {
return {
...val,
category: 'ApplicationEvent',
eventCode: 'REQUEST_FAILED'
};
}
})