-
Notifications
You must be signed in to change notification settings - Fork 878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to serialize the whole object, not properties? #362
Comments
This is the same thing as pinojs/pino-http#42 (pinojs/pino-http#43). The solution is to split out the standard serializers into I'll start work on this. |
@jsumners While my question is more like - maybe we should have the control over the whole object serialisation. Like providing the option to register serializer called |
The solution is merely centralizing this code so that we don't have to update it in 15 places every time someone finds a bug. |
As for:
You can supply your own serializers any time you like -- https://getpino.io/#/docs/API?id=constructor ( |
@jsumners in my example I made an assumption that I want to do certain serializations ONLY if all the three parameters are present in the object This is not achievable currently, if I'm right, because current serialiizer implementation is 1 to 1 (object which is being logged property vs |
I'm sorry, I do not understand what you are asking. |
no problem, code speaks better: const pino = require('pino')({
serializers: {
// this works, if a is there, it will be invoked
a: function(v) {
console.log(arguments);
return {I: "am", not: "the a", you: "are", looking: "for"}
},
// this is not real, this is what I suggest to have
'*': function(obj) {
if(obj.b == 99) {
obj.a = 88;
return obj;
}
return obj;
}
}
});
pino.info({a:'hello'});
pino.info({a:'hello', b: 99}); What I'm articulating right now, that with the current structure of the |
I think this should be closed as well. |
@mcollina |
@PavelPolyakov that's interesting. Would you like to send a PR? |
@mcollina for now I solved my issue by conditioning in properties serialisers. |
Solved by #365. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hello,
Please, advice what is expected way to achieve the desired behaviour.
I use
pino
through fastify, therefore I use it usually through the request directly:Imagine the next code:
axios
will throw theerror
with the GIANT object, like:https://pastebin.com/ZXccMRvw
pino
will try to log it, while I want to work on the serialisation of the logged object.BUT, serializers object supports only per property serialization. In my case these are three properties
request
,response
,config
only the fact that three of them are present is the evidence of theaxios
error.How can I put the logic on top three of them together, not one by one? Let's say if only
config
is present - I want to log it as is.I actually achieved it with
prettyPrint
, but when I tried to test this using unit-tests, and declared the custom write stream - pino init fails, sinceprettyPrint
is not available if you are not usingprocess.stdout
.What can be done about it?
Regards,
The text was updated successfully, but these errors were encountered: