Open veerugp opened 4 years ago
The docs say this about the logPayload
option:
When enabled, add the request payload as payload to the response event log.
So it seems to be to be intended that only the request payload is logged, not the response.
However I'd also like to be able to log the response payload for troubleshooting purposes, there doesn't seem to be an option for this.
You can do this with a formatter:
import _ from "lodash";
const plugin = {
plugin: require("hapi-pino"),
options: {
formatters: {
log(object: any) {
const body = _.get(object, "req.response.source");
if (body) {
return {
...object,
body,
};
} else {
return object;
}
}
}
},
};
very helpful. Thanks
My code is a follows:
Logs are as shown as below:
Response body is showing as
"res":{}
How to get the response body value, which is
{'test':'Resp Msg'}