I have the following log4perl.conf configuration file that I'm using for multiple scripts. It is configured to show messages from all log levels.
# Log4perl configuration file
log4perl.rootLogger = ALL, screen, file
log4perl.appender.screen = Log::Log4perl::Appender::Screen
log4perl.appender.screen.stderr = 0
log4perl.appender.screen.layout = PatternLayout
log4perl.appender.screen.layout.ConversionPattern = %d %p> %m%n
log4perl.appender.file = Log::Log4perl::Appender::File
log4perl.appender.file.filename = sub { my $script=$0; $script =~ s/(dev|test|prod)\/script/log/; $script =~ s/\.[^.]+$//; return "$script.log" }
log4perl.appender.file.mode = append
log4perl.appender.file.layout = PatternLayout
log4perl.appender.file.layout.ConversionPattern = %d %p> %m%n
The scripts use this code snippet to initialize it:
use Log::Log4perl;
# Logger configuration
Log::Log4perl->init('/etc/log4perl.conf');
$logger = Log::Log4perl->get_logger();
What is the best way to adjust the logging level without having to modify the configuration file each time since there are multiple scripts using the same config.
Can I create a new logger and have the script use that one instead of the root logger?