Skip to content

Request logging customization #4463

@kibertoad

Description

@kibertoad

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

Expose fastify param createRequestLogMessage, which would allow customizing request param log message.

Motivation

Currently logic for request logging looks like this:

    if (disableRequestLogging === false) {
      childLogger.info({ req: request }, 'incoming request')
    }

It is not possible to customize it, which may sometimes be desireable.

Example

It would be great to be able to replace incoming request with a custom-built message. So something like

    if (disableRequestLogging === false) {
      childLogger.info({ req: request }, createRequestLogMessage(req))
    }

createRequestLogMessage would default to a function which returns 'incoming request'.

Full usage example:

  const app = fastify({
    createRequestLogMessage: (req) => { return `${req.id}: incoming request`
  })

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestNew feature to be addedsemver-minorIssue or PR that should land as semver minor

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions