Overrides the log level of the Appender/Logger that this filter is attached to to with level. See also with_log_level(). It is recommended to use filters that modify LogEvents only with Loggers, but they will also work with Appenders.

Super class

lgr::EventFilter -> FilterForceLevel

Public fields

level

an integer log level used to override the log levels of each LogEvent processed by this filter.

Methods

Inherited methods


    Method new()

    Initialize a new FilterForceLevel

    Usage

    FilterForceLevel$new(level)

    Arguments

    level

    an integer or character log level


    Method clone()

    The objects of this class are cloneable with this method.

    Usage

    FilterForceLevel$clone(deep = FALSE)

    Arguments

    deep

    Whether to make a deep clone.

    Examples

    lg <- get_logger("test")
    
    analyse <- function(){
      lg$add_filter(FilterForceLevel$new("info"), "force")
      on.exit(lg$remove_filter("force"))
      lg$error("an error with forced log level INFO")
    }
    
    analyse()
    #> INFO  [20:04:27.246] an error with forced log level INFO
    lg$error("an normal error")
    #> ERROR [20:04:27.249] an normal error
    lg$config(NULL)  # reset config
    #> <Logger> [info] test
    #> 
    #> inherited appenders:
    #>   console: <AppenderConsole> [all] -> console