Hello all,

I'd like to check if there's already a solution to my need, since I
assume it probably reasonably common need.

And second, I'd like to confirm a bug before submitting a ticket.


What I'm after is to have an email sent *as soon* as an error is
detected.  But, then to collect any more errors for a few minutes
before sending another email again to keep from flooding with email.

(I also want to report to Nagios, but that's later.)


Log::Dispatch::Email has a "buffered" option but I'm not sure that
fits with the above.

Any existing solutions for the above?


What I'm attempting to do instead is have a separate File appender
that only logs ERROR and above to a file, then watch that file.

The idea is to have a cron job run often and look for the file to not
be empty.  If found not to be empty do an atomic rename, sleep a few
seconds, then email the file.

Any new log message will be written to a new file.

Then when the cron script runs again look for that *new* file name and
exit if it's found and less than X number of minutes old.  Once it is
X minutes old then look again for a non-empty log file and repeat the
process.



Now, for that to work it's important that the File appender notices
that the file has changed once moved.  The File appender docs say for
"recreate_check_interval":

    This obviously means that the appender will continue writing to a
    moved file until the next check occurs, in the worst case this
    will happen recreate_check_interval seconds after the file has
    been moved or deleted. If this is undesirable, setting
    recreate_check_interval to 0 will have the appender check
    the file with every call to log().

So I have these settings for my appender:

    .recreate = 1
    .recreate_check_interval = 0

But, that is not working -- the move is not detected.

I suspect it's this code in A::File that is checking if
recreate_check_interval is true or not, not if it's defined:

    if($self->{recreate}) {
        $self->{watcher} = Log::Log4perl::Config::Watch->new(
            file           => $self->{filename},
            ($self->{recreate_check_interval} ?
              (check_interval => $self->{recreate_check_interval}) : ()),
            ($self->{recreate_check_signal} ?
              (signal => $self->{recreate_check_signal}) : ()),
        );
    }

and thus Log::Log4perl::Config::Watch falls back to the default of 30
seconds.  Am I configuring this incorrectly or is this a bug?


As a workaround I can set recreate_check_interval to 1, then just make
sure I sleep to catch anything else that might get written to the
renamed file.



Finally, another question.  I've got three appenders.  One for syslog,
one for stderr, and one to a file.

Is it possible to set a pattern that will apply to all?  Or do I have
to specify a pattern for each appender?


log4perl.rootLogger = INFO, syslogAppender, screenAppender, errorNotify

## syslog ##
log4perl.appender.syslogAppender = Log::Dispatch::Syslog
log4perl.appender.syslogAppender.utf8     = 1
log4perl.appender.syslogAppender.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.syslogAppender.layout.ConversionPattern \
    = [%p] "%m" pid:%P [%X{ip}] "%X{uri}"


## screen ##
log4perl.appender.screenAppender = Log::Log4perl::Appender::Screen
log4perl.appender.screenAppender.utf8     = 1
log4perl.appender.screenAppender.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.screenAppender.layout.ConversionPattern \
    = %d{MMM dd HH:mm:ss} [%p] "%m" pid:%P [%X{ip}] "%X{uri}"%n



## File -- Just ERRORs ##
log4perl.appender.screenAppender.layout.ConversionPattern \
    = %d{MMM dd HH:mm:ss} [%p] "%m" pid:%P [%X{ip}] "%X{uri}"%n


log4perl.appender.errorNotify = Log::Log4perl::Appender::File
log4perl.appender.errorNotify.filename = error.log
log4perl.appender.errorNotify.mode = append

# We want this to recreate the file if it's moved
log4perl.appender.errorNotify.recreate = 1
## This does not work
log4perl.appender.errorNotify.recreate_check_interval = 0

# And only log errors
log4perl.appender.errorNotify.Threshold  = ERROR

log4perl.appender.errorNotify.utf8     = 1
log4perl.appender.errorNotify.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.errorNotify.layout.ConversionPattern \
    = %d{MMM dd HH:mm:ss} [%p] "%m" pid:%P [%X{ip}] "%X{uri}"%n







I



-- 
Bill Moseley
[EMAIL PROTECTED]


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel

Reply via email to