Search code examples
perlapacheloggingmod-perllog4perl

Can Perl's Log::Log4perl's log levels be changed dynamically without updating config?


I have a Mason template running under mod_perl, which is using Log::Log4perl.

I want to change the log level of a particular appender, but changing the config is too awkward, as it would have to pass through our deployment process to go live.

Is there a way to change the log level of an appender at run-time, after Apache has started, without changing the config file, and then have that change affect any new Apache threads?


Solution

  • If you've imported the log level constants from Log::Log4perl::Level, then you can do things like:

    $logger->level($ERROR); # one of DEBUG, INFO, WARN, ERROR, FATAL
    
    $logger->more_logging($delta); # Increase log level by $delta levels,
                                   # a positive integer
    
    $logger->less_logging($delta); # Decrease log level by $delta levels.
    

    This is in the Changing the Log Level on a Logger section in the Log::Log4perl docs.