fng has asked for the wisdom of the Perl Monks concerning the following question:

I may just be blind but I couldn't find a way to get the standard log4perl file appender's recreate_check_signal behavior using a signal that I am already catching. I'd love to rotate the log with logrotate and tell it what signal to send, but I'm already using usr1, usr2, and hup. To make matters worse, it's an event driven server (currently using libevent). So I really want to manage my own %SIG hash. But L4P really seems to only like installing and managing its own signal handler, which I believe it reinstalls if the config file is changed while init_and_watch is in effect. Is there some API to L4P that I missed which I could call to tell it to check for moved files?

Replies are listed 'Best First'.
Re: Log4Perl Share Signals
by andreas1234567 (Vicar) on Feb 06, 2009 at 07:22 UTC
    Automatic reloading of changed configuration files:
    To alleviate this performance hit a bit, init_and_watch() can be configured to listen for a Unix signal to reload the configuration instead:
    Log::Log4perl->init_and_watch($conf_file, 'HUP');
    This will set up a signal handler for SIGHUP and reload the configuration if the application receives this signal, e.g. via the kill command:
    kill -HUP pid
    where pid is the process ID of the application.
    Log::Log4perl::Config::Watch:
    SIGNAL MODE

    Instead of polling time and file changes, new() can be instructed to set up a signal handler. If you call the constructor like

    my $watcher = Log::Log4perl::Config::Watch->new( file => "/data/my.conf", signal => 'HUP' );
    then a signal handler will be installed, setting the object's variable $self->{signal_caught} to a true value when the signal arrives. Comes with all the problems that signal handlers go along with.
    --
    No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]