Skip to content

Serializer per context #1845

@Eomm

Description

@Eomm

🚀 Feature Proposal

I would like to have the possibility to customize the logger serializer per context so,
in one context I can log a user with the serializerA, and in another context I can use the serializerB.

Pino support the serializers configuration in the child logger, where you can overwrite the serializer defined in the parent logger or simply add new ones.

Motivation

I'm using a JSON schema to drop all the data that I don't want to log out.
In some context I need to see a field with many info, in another context I don't need it

Example

fastify.register(require('./user'), {
  logLevel: 'debug',
  serializers: {
    user: jsonSchemaSerializer(mySchema)
  }
})

fastify.register(require('./special-user'), {
  logLevel: 'debug',
  serializers: {
    user: jsonSchemaSerializer(myOtherSchema)
  }
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions