OK, so I take the example from the Schedule::Cron manpage and modify it with config settings as in the Log4perl manpage, as below, and it logs nothing at all, and the script dies.
my $log_method = sub { my ($level,$msg) = @_; my $DBG_MAP = { 0 => $INFO, 1 => $WARN, 2 => $ERROR }; my $conf = q( log4perl.category.appname = INFO, Logfile log4perl.appender.Logfile = Log::Log4perl::Ap +pender::File log4perl.appender.Logfile.filename = /usr/local/eFTP/l +ogs/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 = Log::Log4Perl->get_logger("appname"); $logger->log($DBG_MAP->{$level},$msg); };
and modify the cron job to reflect that:
my $cron = new Schedule::Cron(\&dispatcher, nofork => 1, #log => \&Log, log => $log_method, ); $cron->add_entry("* * * * *", {'subroutine' => \&TestSub(), 'arguments' => [ "INFO", "a test" ], } );
I also removed the call to my Log(..) subroutine in TestSub, since it's redefined and used here in $log_method.

Again, now there's nothing logged to the file at all. The file /tmp/testfile is updated, so I know TestSub ran, but nothing updated in appname.pl.log, and no Schedule::Cron process in the process table after a couple minutes.

Is there something I'm not setting the Schedule::Cron object? What else could be causing not to log at all, much less quit?

-- Burvil


In reply to Re^2: Log4perl script logs OK only initially by bowei_99
in thread Log4perl script logs OK only initially by bowei_99

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.