Why does USR1 seem to kill Perl rather than recreate the log file?

I have a Perl script to which I added the registration, kindly provided by Log4perl .

The script itself works for a long time, and we also need to do logarithms / archiving daily.

I decided to use the built-in Solaris logadminstead of using Log :: Dispatch :: FileRotate , because

  • we are trying to reduce the number of Perl dependencies we need and
  • I get the impression that doing this at the OS level outside of your application is the preferred / most reliable approach.

As part of the rotation, I also need to get a Perl script to update its file descriptor. According to the Frequently Asked Questions Log4perl, you can configure it to listen to the USR1 signal and recreate the file descriptors on this:

log4perl.rootLogger                                     = DEBUG, INFOLOG, DEBUGLOG

log4perl.appender.INFOLOG                               = Log::Log4perl::Appender::File
log4perl.appender.INFOLOG.filename                      = myprogram.info.log
log4perl.appender.INFOLOG.mode                          = append
log4perl.appender.INFOLOG.recreate                      = 1
log4perl.appender.INFOLOG.recreate_check_signal         = USR1
log4perl.appender.INFOLOG.layout                        = Log::Log4perl::Layout::PatternLayout
log4perl.appender.INFOLOG.layout.ConversionPattern      = %d [%p] (%F line %L) %m%n
log4perl.appender.INFOLOG.Threshold                     = INFO

log4perl.appender.DEBUGLOG                              = Log::Log4perl::Appender::File
log4perl.appender.DEBUGLOG.filename                     = myprogram.debug.log
log4perl.appender.DEBUGLOG.mode                         = append
log4perl.appender.INFOLOG.recreate                      = 1
log4perl.appender.INFOLOG.recreate_check_signal         = USR1
log4perl.appender.DEBUGLOG.layout                       = Log::Log4perl::Layout::PatternLayout
log4perl.appender.DEBUGLOG.layout.ConversionPattern     = %d [%p] (%F line %L) %m%n

However, for some reason, when I send the USR1 signal to the Perl process, my Perl script just exits.

I am sending it with:

kill -s USR1 <pid>

As soon as I do this, the Perl process seems to die. This happens if I configured Log4perl to capture USR1 or not.

I also tried using USR2, the same effect.

Is there something obvious I'm missing here, either in Log4perl, or in Perl or Solaris?

+3
source share
1 answer

DEBUGLOG INFOLOG, . , , , :

# Your Log4perl config

Log::Log4perl::init( \$conf );

my $log = Log::Log4perl::get_logger("Foo::Bar");

while (1){
  $log->info("Important Info!");
  sleep 5;
}

( Mac), , Solaris. , .

0

Source: https://habr.com/ru/post/1795930/


All Articles