pino icon indicating copy to clipboard operation
pino copied to clipboard

Custom req serializer example?

Open jp-23 opened this issue 6 years ago • 3 comments

Hello,

How do I create a custom req serializer? I see documentation regarding the default req serializer, and I see that custom serializers can be created, but I haven’t found a good example of how to do this, or any best practices? e.g. the default req serializer has a ‘raw’ field - should I include this as well in my custom req serializer (is it needed by the internals of pino?), and if so, how (e.g. just use: ‘raw: req’)?

Thanks!

jp-23 avatar Oct 06 '19 14:10 jp-23

The default request serializer is https://github.com/pinojs/pino-std-serializers . This serializer is extensible and thus exposes information necessary for downstream tools to do their work. Any implementation that doesn't extend that serializer simply receives whatever value is attached to the to-be-serialized property, and the logger logs whatever string comes out of the serializer.

jsumners avatar Oct 07 '19 11:10 jsumners

I want to echo the request for an example - I like this library a lot, and would find it extremely helpful to see a simple, nontrivial example.

There actually are examples in the pino-std-serializers tests (here's one for requests: https://github.com/pinojs/pino-std-serializers/blob/master/test/req.test.js#L210 ) but it would be great to make them easier to find, and a bit more friendly / fleshed out for nontrivial use cases.

I will try to follow up w/a PR w/an example if I get my serializer working.

adamcee avatar Nov 05 '19 08:11 adamcee

Thanks for the feedback! Would you mind to send a PR?

mcollina avatar Nov 05 '19 09:11 mcollina