Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom or add more property to logger in logRequestCompleted #135

Open
lytaitruong opened this issue Mar 24, 2021 · 2 comments
Open

Custom or add more property to logger in logRequestCompleted #135

lytaitruong opened this issue Mar 24, 2021 · 2 comments

Comments

@lytaitruong
Copy link

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.

@mcollina
Copy link
Collaborator

I'm not really a Hapi user anymore, can't really help.

@felixheck
Copy link
Collaborator

Hey @lytaitruong,
it might help to look at the source code of laabr — a wrapper around hapi-pino to make customizations to all kind of logs easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants