Subject: | MooseX::Daemonize does not work with Log4perl |
When using Log::Log4perl to log in a MooseX::Daemonize daemon the daemon
does not start. Furthermore, I sometimes find log messages in the pid
file even though they have different names.
The attached module and start file explains the issue. When running it,
I'd expect the daemon to start, write "Started daemon" to the log file,
write "Log 1", "Log 2", "Log 3" to the logfile and then continue to run
until /tmp/stopit exists.
Instead it starts, writes "Started daemon" and then disappears without
further notice.
I consider this a critical issue since Log4perl is probably one of the
most important ways to log from a daemon.
Subject: | exp-daemon |
Message body not shown because it is not plain text.
Subject: | Daemon.pm |
package Exp::Daemon;
use warnings;
use strict;
use Moose;
with 'MooseX::Daemonize';
with 'MooseX::Log::Log4perl';
after start => sub {
my ($self) = @_;
return unless $self->is_daemon;
$self->log->error("Log 1");
$self->log->error("Log 2");
$self->log->error("Log 3");
while (not -e '/tmp/stopit') {
sleep 5;
}
};
sub run
{
my ($self) = @_;
my ($command) = @{$self->extra_argv};
defined $command || die "No command specified";
$self->status if $command eq 'status';
$self->restart if $command eq 'restart';
$self->stop if $command eq 'stop';
# $self->start if $command eq 'start';
if ($command eq 'start') {
use Log::Log4perl;
my $string = '
log4perl.rootLogger = ALL, file
log4perl.appender.file = Log::Log4perl::Appender::File
log4Perl.appender.file.filename = /tmp/exp_daemon_logfile
log4perl.appender.file.layout = PatternLayout
log4perl.appender.file.layout.ConversionPattern = %d %p %c - %m in %F{2} (%L)%n
';
Log::Log4perl->init(\$string);
$self->log->info("Started daemon");
$self->start;
}
}
1; # End of Exp::Daemon