8000 feat: support customAttributeKeys in logger serializers by RafaelMeir4 · Pull Request #6405 · fastify/fastify · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@RafaelMeir4
Copy link

Closes #4413

Summary

This PR adds support for customAttributeKeys option in the logger configuration, allowing users to customize the attribute keys used in log records (req, res, err).

This is particularly useful for cloud logging platforms like Google Cloud Logging, which expect specific field names (e.g., httpRequest instead of req).

Example Usage

const fastify = require('fastify')({
  logger: {
    level: 'info',
    customAttributeKeys: {
      req: 'httpRequest',
      res: 'response',
      err: 'error'
    },
    serializers: {
      req: function (req) {
        return {
          requestMethod: req.method,
          requestUrl: req.url,
          userAgent: req.headers['user-agent'],
          remoteIp: req.headers['x-forwarded-for']
        }
      }
    }
  }
})

Checklist

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support pino logger customAttributeKeys to replace existing req res reqId log record fields

1 participant

0