メモ
use strict; use warnings; use Date::Calc; use Log::Log4perl; my $CONF = {log=> { # 'log4perl.rootLogger'=> 'INFO, LOGFILE', 'log4perl.rootLogger'=> 'DEBUG, LOGFILE, CONSOLE', 'log4perl.appender.LOGFILE'=>'Log::Log4perl::Appender::File', #↓ココ。「1」でバッファリング防止 'log4perl.appender.Logfile.autoflush' => 1, 'log4perl.appender.LOGFILE.dir'=> $APP_ROOT, 'log4perl.appender.LOGFILE.filename'=> $APP_ROOT. 'migrate.log', 'log4perl.appender.LOGFILE.mode'=>'append', 'log4perl.appender.LOGFILE.layout'=>'Log::Log4perl::Layout::PatternLayout', 'log4perl.appender.LOGFILE.layout.ConversionPattern'=>'%d [%p] %m %n', 'log4perl.appender.CONSOLE'=> 'Log::Log4perl::Appender::Screen', 'log4perl.appender.CONSOLE.layout' => 'Log::Log4perl::Layout::PatternLayout', 'log4perl.appender.CONSOLE.layout.ConversionPattern' => '%d [%p] %m %n'}, }; my $LOGGER; sub do_main { my ($self ) = @_; $LOGGER = init_logger(); $LOGGER->error($tmp_msg); } sub init_logger { Log::Log4perl::init($CONF->{log}); my $logger = Log::Log4perl::get_logger("rootLogger"); unless($logger){ die "fail init_logger() $!"; } return $logger; }