Custom or add more property to logger in logRequestCompleted
- Dominant language
- JavaScript
- Stars
- 147
- Forks
- 56
- PR merge metrics
- No merged PRs in 30d
Description
I've looked at the library and found can't be edit or format custom log in events 'response' when logRequestCompleted: true
log when a request completed
I try to add more field in ```request.raw.res``` but in HAPI docs say "not recommend to do it"
```
request.logger.info(
{
payload: options.logPayload ? request.payload : undefined,
queryParams: options.logQueryParams ? request.query : undefined,
tags: options.logRouteTags ? request.route.settings.tags : undefined,
// note: pino doesnt support unsetting a key, so this next line
// has the effect of setting it or "leaving it as it was" if it was already added via child bindings
req: shouldLogRequestStart(request) ? undefined : request,
res: request.raw.res,
responseTime: (info.completed !== undefined ? info.completed : info.responded) - info.received
myCustomField: myValue
},
'request completed'
)
```
Why I need it: When I using ELK to trace the issue, I need to add x-request-id to know the flow of the request so it makes me terrible. So if I can add more property like errorCode or errorMessage in the only request completed to trace easier
Thank for support.
Contributor guide
Research direction
Start at the library's logRequestCompleted handling and trace how the completed-request log object is assembled. Determine how callers could supply fields such as x-request-id, errorCode, or errorMessage without modifying request.raw.res; done means custom fields appear only in the completed-request log and the relevant behavior is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend, observability
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100