Closed venkatd closed 3 years ago
I was just looking for exactly this functionality and I think it would be a nice enhancement.
@mercutiodesign for now your best bet would be to implement your own printer by copying/pasting the closest one to what you need. Can check if the message is a function and evaluate it before you print.
I rather like the idea! Since the message
argument to a log call (like d
) is dynamic
already this should be relatively straightforward.
Hi, needed exactly the same but saw that there is no PR for this, so I just did it. See #105
Closed since #105 is merged.
Some of our logger statements involve expensive computations like formatting objects to make the logs easy to read. To work around this, we are passing functions for the expensive log statements and they are getting evaluated in the printer right before they need to be printed.
For example:
summarizeGqlPayload
in this case is relatively expensive and something we wouldn't want to be execute in production. Or at least all these little things add up to increased CPU usage. Hence we are passing a function.Our corresponding
stringify
in our custom logger looks something like this to handle functions.Is this worth having as a default for the logger?