# NOT RUN {
# using filters to modify log events
lg <- get_logger("test")
analyse <- function(){
lg$add_filter(FilterForceLevel$new("info"), "force")
lg$add_filter(FilterInject$new(type = "analysis"), "inject")
on.exit(lg$remove_filter(c("force", "inject")))
lg$debug("a debug message")
lg$error("an error")
}
analyse()
lg$error("an error")
lg$config(NULL) # reset config
# using .obj()
lg <- get_logger("test")
f <- function(event) {
cat("via event$.logger:", event$.logger$threshold, "\n") # works for loggers only
cat("via .obj(): ",.obj()$threshold, "\n") # works for loggers and appenders
TRUE
}
lg$add_filter(f)
lg$fatal("test")
lg$config(NULL)
# }
Run the code above in your browser using DataLab