pino
pino copied to clipboard
Custom req serializer example?
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!
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.
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.
Thanks for the feedback! Would you mind to send a PR?