Inject arbitrary values into all LogEvents processed by a Logger/Appender. It is recommended to use filters that modify LogEvents only with Loggers, but they will also work with Appenders.
lgr::EventFilter
-> FilterInject
values
a named list
of values to be injected into each
LogEvent processed by this filter
Inherited methods
new()
Initialize a new FilterInject
FilterInject$new(..., .list = list())
..., .list
any number of named R objects that will be injected as
custom fields into all LogEvents processed by the
Appender/Logger that this filter is attached to. See also
with_log_value()
.
lg <- get_logger("test")
analyse <- function(){
lg$add_filter(FilterInject$new(type = "analysis"), "inject")
on.exit(lg$remove_filter("inject"))
lg$error("an error with forced custom 'type'-field")
}
analyse()
#> ERROR [20:04:27.715] an error with forced custom 'type'-field {type: `analysis`}
lg$error("an normal error")
#> ERROR [20:04:27.725] an normal error
lg$config(NULL) # reset config
#> <Logger> [info] test
#>
#> inherited appenders:
#> console: <AppenderConsole> [all] -> console