You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have hundreds of possible log fields, and I'd like to make sure that my logs are formatted consistently between the different loggers in my applications.
For example, if a field is named method, I'd like its contents to always be in UPPERCASE.
For example, if called as follows:
logger.info({msg: 'HTTP call',method: 'post'});
It should always be logged in this way:
{ "msg": "HTTP call", "method": "POST" }
Or so that another body field is always serialized in JSON, for example, if it is called as follows:
With this in mind, I thought I'd use a function for the bindings and log formatters that centralizes the modifications to be made to the objects passed as parameters.
For example, in the code below, the shapeObject function, which converts the values of the method, logger and partner fields to uppercase and serializes the value of the body field to JSON, is used as the formatter for log and bindings formatters:
I've opened Pull Request 1950 a few months ago to show an example of a modification that would allow me this behavior by adding an options object, which shouldn't add too much overhead.
But maybe there's another way to do it in a more clean/optimized way?
The text was updated successfully, but these errors were encountered:
I have hundreds of possible log fields, and I'd like to make sure that my logs are formatted consistently between the different loggers in my applications.
For example, if a field is named
method
, I'd like its contents to always be in UPPERCASE.For example, if called as follows:
It should always be logged in this way:
Or so that another
body
field is always serialized in JSON, for example, if it is called as follows:It should always be logged this way:
With this in mind, I thought I'd use a function for the
bindings
andlog
formatters that centralizes the modifications to be made to the objects passed as parameters.For example, in the code below, the
shapeObject
function, which converts the values of themethod
,logger
andpartner
fields to uppercase and serializes the value of thebody
field to JSON, is used as the formatter forlog
andbindings
formatters:The above code gives me the following result:
My problems are as follows:
log
formatter, thebindings
formatting is not applied to child logs in the same way as to parent logs.bindings
passed when callingchild()
(chindings
) are not formatted.How can I get the following result instead?
I've opened Pull Request 1950 a few months ago to show an example of a modification that would allow me this behavior by adding an options object, which shouldn't add too much overhead.
But maybe there's another way to do it in a more clean/optimized way?
The text was updated successfully, but these errors were encountered: