Skip to content

Custom or add more property to logger in logRequestCompleted  #135

@lytaitruong

Description

@lytaitruong

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions