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
This may be a documentation issue, but it seems like there is no easy way to add custom keys to a log event. I initially expected to be able to simply do something like
TransformerLogger(current_logger()) do log
merge(log, (; newkey="value"))
end
but that doesn't work, because apparently TransformerLogger should return a named tuple with specific fields, and the custom key-value pairs are in a kwargs field. Writing to that field also doesn't work because that would change its type.
After digging around the package code, the easiest solution I came up with was calling LoggingExtras.handle_message_args (which is not mentioned in the docs), and using to the replace the event with a new one:
function merge_log_event(event; kwargs...)
args = Tuple(event)[1:end-1] # to drop the kwargs field
LoggingExtras.handle_message_args(args...; kwargs..., event.kwargs...)
end
logger = TransformerLogger(current_logger()) do event
merge_log_event(event; newkey="value")
end
Maybe something like this should be provided in the package?
The text was updated successfully, but these errors were encountered:
Yes, so what you need to do is access that field to get the old kwargs,
and then use that to build new kwargs,
which you then need to use to build a new log message.
We can't put them at the top-level, with the standard parts of the log message,
as that would disallow working with custom kwargs with names like msg,
since that would clash with actual message.
Following is an example of how to do this.
A PR to add something similar to the readme would be appreciated.
julia> @info "Hi"
┌ Info: Hi
└ timestamp = 2019-09-23T11:02:19.403
After digging around the package code, the easiest solution I came up with was calling LoggingExtras.handle_message_args (which is not mentioned in the docs),
handle_message_args is mentioned in the docstring for TransformLogger.
But only because it contains the definitions of what each arg is.
Those defintions maybe should be moved elsewhere. handle_message_args is not part of the public API.
It should never need to be invoked by the user of this package.
It is a internal helper function for building the single log_args nametuple out of the mix of positional and kwargs that default logging interface uses.
This may be a documentation issue, but it seems like there is no easy way to add custom keys to a log event. I initially expected to be able to simply do something like
but that doesn't work, because apparently
TransformerLogger
should return a named tuple with specific fields, and the custom key-value pairs are in akwargs
field. Writing to that field also doesn't work because that would change its type.After digging around the package code, the easiest solution I came up with was calling
LoggingExtras.handle_message_args
(which is not mentioned in the docs), and using to the replace the event with a new one:Maybe something like this should be provided in the package?
The text was updated successfully, but these errors were encountered: