bowei_99 has asked for the wisdom of the Perl Monks concerning the following question:
I've written a script to ping servers using a Schedule::Cron job and log using Log4perl. It logs the first time the cron job runs, but thereafter, it simply logs a blank message:
I know the cron job is writing correctly, as the testfile shows the correct times:2007/12/28 22:16:00 test.pl 84> INFO: this is a test 2007/12/28 22:16:00 test.pl 84> 0: 2007/12/28 22:17:00 test.pl 84> 0: 2007/12/28 22:17:00 test.pl 84> INFO: this is a test 2007/12/28 22:17:00 test.pl 84> 0: 2007/12/28 22:18:00 test.pl 84> 0: 2007/12/28 22:18:00 test.pl 84> INFO: this is a test 2007/12/28 22:18:00 test.pl 84> 0:
I doublechecked and found no other test.pl processes running.# tail /tmp/testfile Fri Dec 28 22:12:00 GMT 2007 ... Fri Dec 28 22:18:00 GMT 2007 Fri Dec 28 22:19:00 GMT 2007 Fri Dec 28 22:20:00 GMT 2007 Fri Dec 28 22:21:00 GMT 2007
My guess is that it's finding null for level, converting to int, and printing it... but I don't understand why.
As I'm not sure if Schedule::Cron is passing the data correctly or whether something is amiss with Log4perl , I've included the code below.
Thoughts, anyone?
#!/usr/bin/perl use Data::Dumper; use Carp; use Schedule::Cron; use Sys::Hostname; use Log::Log4perl qw(get_logger); ############################################### #Variable declarations my $rootdir = "/usr/local/appname"; my $script = "test"; ############################################### #MAIN #OpenLog ($logfile); my $cron = new Schedule::Cron(\&dispatcher, nofork => 1, log => \&Log, ); $cron->add_entry("* * * * *", {'subroutine' => \&TestSub, } ); $cron->run(detach=>1, pid_file=>"$rootdir/bin/$script.pid"); ###################################################### sub dispatcher { print "ID: ",shift,"\n"; print "Args: ","@_","\n"; } ###################################################### sub TestSub { Log ("INFO", "", "this is a test"); `date >> /tmp/testfile`; } ###################################################### sub Log { my ($level, $subject, $msg) = @_; my $conf = q( log4perl.category.appname = INFO, Logfile log4perl.appender.Logfile = Log::Log4perl::Append +er::File log4perl.appender.Logfile.filename = /usr/local/appname/lo +gs/appname.pl.log log4perl.appender.Logfile.layout = \ Log::Log4perl::Layout::PatternLayout log4perl.appender.Logfile.layout.ConversionPattern = %d %F +{1} %L> %m %n ); Log::Log4perl::init(\$conf); my $logger = get_logger("appname"); $logger->info("$level: $msg"); if ($level eq "ERR") { $logger->error($msg); } }
-- Burvil
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Log4perl script logs OK only initially
by jasonk (Parson) on Dec 29, 2007 at 01:01 UTC | |
by bowei_99 (Friar) on Dec 30, 2007 at 05:54 UTC | |
by bowei_99 (Friar) on Jan 02, 2008 at 18:10 UTC |