From: Bill M. <mo...@ha...> - 2008-05-08 04:58:14
|
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 mo...@ha... |
From: Jonathan S. <sw...@po...> - 2008-05-09 18:25:12
|
I've got a growing number of log files for different categories that I would like to all have the same layout and pattern, e.g. log4perl.appender.file1 = Log::Log4perl::Appender::File log4perl.appender.file1.filename = /path/to/ logfile/1 log4perl.appender.file1.layout = PatternLayout log4perl.appender.file1.layout.ConversionPattern = %d{dd/MMM/ yyyy:HH:mm:ss.SS} [%p] %c - %m - %F:%L %P-%n log4perl.appender.file2 = Log::Log4perl::Appender::File log4perl.appender.file2.filename = /path/to/ logfile/2 log4perl.appender.file2.layout = PatternLayout log4perl.appender.file2.layout.ConversionPattern = %d{dd/MMM/ yyyy:HH:mm:ss.SS} [%p] %c - %m - %F:%L %P-%n log4perl.appender.file3 = Log::Log4perl::Appender::File log4perl.appender.file3.filename = /path/to/ logfile/3 log4perl.appender.file3.layout = PatternLayout log4perl.appender.file3.layout.ConversionPattern = %d{dd/MMM/ yyyy:HH:mm:ss.SS} [%p] %c - %m - %F:%L %P-%n In the spirit of DRY, I'd like to eliminate those repeated layout and layout.ConversionPattern lines. What's the best way to do this? I'm happy to create whatever subclasses necessary, but looking at the Appender, Appender::File, Layout, and Layout::PatternLayout classes, it wasn't clear to me what to subclass. Thanks Jon |
From: Jonathan S. <sw...@po...> - 2008-05-12 21:21:46
|
I've got a growing number of log files for different categories that I would like to all have the same layout and pattern, e.g. log4perl.appender.file1 = Log::Log4perl::Appender::File log4perl.appender.file1.filename = /path/to/ logfile/1 log4perl.appender.file1.layout = PatternLayout log4perl.appender.file1.layout.ConversionPattern = %d{dd/MMM/ yyyy:HH:mm:ss.SS} [%p] %c - %m - %F:%L %P-%n log4perl.appender.file2 = Log::Log4perl::Appender::File log4perl.appender.file2.filename = /path/to/ logfile/2 log4perl.appender.file2.layout = PatternLayout log4perl.appender.file2.layout.ConversionPattern = %d{dd/MMM/ yyyy:HH:mm:ss.SS} [%p] %c - %m - %F:%L %P-%n log4perl.appender.file3 = Log::Log4perl::Appender::File log4perl.appender.file3.filename = /path/to/ logfile/3 log4perl.appender.file3.layout = PatternLayout log4perl.appender.file3.layout.ConversionPattern = %d{dd/MMM/ yyyy:HH:mm:ss.SS} [%p] %c - %m - %F:%L %P-%n In the spirit of DRY, I'd like to eliminate those repeated layout and layout.ConversionPattern lines. What's the best way to do this? I'm happy to create whatever subclasses necessary, but looking at the Appender, Appender::File, Layout, and Layout::PatternLayout classes, it wasn't clear to me what to subclass. Thanks Jon |
From: Bill M. <mo...@ha...> - 2008-05-12 21:48:34
|
On Mon, May 12, 2008 at 02:21:23PM -0700, Jonathan Swartz wrote: > I've got a growing number of log files for different categories that I > would like to all have the same layout and pattern, e.g. You can use "Variable Substitution" as described in the man page, but that still seems awkward. -- Bill Moseley mo...@ha... |
From: Bill M. <mo...@ha...> - 2008-05-13 15:10:30
|
On Mon, May 12, 2008 at 02:21:23PM -0700, Jonathan Swartz wrote: > I've got a growing number of log files for different categories that I > would like to all have the same layout and pattern, e.g. You can use "Variable Substitution" as described in the man page, but that still seems awkward. -- Bill Moseley mo...@ha... |
From: Mike S. <m...@pe...> - 2008-05-13 05:29:54
|
On Fri, 9 May 2008, Jonathan Swartz wrote: > I've got a growing number of log files for different categories that I > would like to all have the same layout and pattern, e.g. Hi Jonathan, this is one of the items on my todo-list: To have an inheritance mechanism that lets you say something like log4perl.appender.file.inherits_from = \ log4perl.appender.file_base and any property you don't specify in 'file' is inherited from file_base. It's not in L4p yet, but hopefully soon! ;) -- Mike Mike Schilli m...@pe... > > log4perl.appender.file1 = > Log::Log4perl::Appender::File > log4perl.appender.file1.filename = /path/to/ > logfile/1 > log4perl.appender.file1.layout = PatternLayout > log4perl.appender.file1.layout.ConversionPattern = %d{dd/MMM/ > yyyy:HH:mm:ss.SS} [%p] %c - %m - %F:%L %P-%n > > log4perl.appender.file2 = > Log::Log4perl::Appender::File > log4perl.appender.file2.filename = /path/to/ > logfile/2 > log4perl.appender.file2.layout = PatternLayout > log4perl.appender.file2.layout.ConversionPattern = %d{dd/MMM/ > yyyy:HH:mm:ss.SS} [%p] %c - %m - %F:%L %P-%n > > log4perl.appender.file3 = > Log::Log4perl::Appender::File > log4perl.appender.file3.filename = /path/to/ > logfile/3 > log4perl.appender.file3.layout = PatternLayout > log4perl.appender.file3.layout.ConversionPattern = %d{dd/MMM/ > yyyy:HH:mm:ss.SS} [%p] %c - %m - %F:%L %P-%n > > In the spirit of DRY, I'd like to eliminate those repeated layout and > layout.ConversionPattern lines. > > What's the best way to do this? I'm happy to create whatever > subclasses necessary, but looking at the Appender, Appender::File, > Layout, and Layout::PatternLayout classes, it wasn't clear to me what > to subclass. > > Thanks > Jon > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > log4perl-devel mailing list > log...@li... > https://lists.sourceforge.net/lists/listinfo/log4perl-devel > |
From: Mike S. <m...@pe...> - 2008-05-13 05:56:35
|
On Wed, 7 May 2008, Bill Moseley wrote: > 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? The way this works in the buffered email appender is actually quite different: It collects messages *until* a threshold is reached, then it sends an email: http://log4perl.sourceforge.net/d/Log/Log4perl/FAQ.html#a0f6e > 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. If you're running a single process (and won't need to keep state on restarts) there's no need to do this in a file appender. You could define your own appender which maintains a (memory) buffer. > So I have these settings for my appender: > > .recreate = 1 > .recreate_check_interval = 0 > > But, that is not working -- the move is not detected. Aha, that's a bug -- I've fixed it in 1.16 in CVS, to be released soon -- thanks! > 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? Variable substitution should help with this: http://log4perl.sourceforge.net/d/Log/Log4perl.html#bd632 -- Mike Mike Schilli m...@pe... |
From: Jonathan S. <sw...@po...> - 2008-05-14 00:47:40
|
> On Fri, 9 May 2008, Jonathan Swartz wrote: > >> I've got a growing number of log files for different categories >> that I >> would like to all have the same layout and pattern, e.g. > > Hi Jonathan, > > this is one of the items on my todo-list: To have an inheritance > mechanism that lets you say something like > > log4perl.appender.file.inherits_from = \ > log4perl.appender.file_base > > and any property you don't specify in 'file' is inherited from > file_base. It's not in L4p yet, but hopefully soon! ;) > That would be great! In the meantime, I might try to do this myself by creating my own Appender subclass: # My::Log4perl::Appender::File defaults to my preferred layout and layout.ConversionPattern log4perl.appender.file1 = My::Log4perl::Appender::File log4perl.appender.file2 = My::Log4perl::Appender::File Do you have a vague idea of how I might approach this? Or is it too diffiicult, and I should just suck up the repetition until the inheritance feature? :) Jon |
From: Mike S. <m...@pe...> - 2008-05-16 06:04:49
|
On Tue, 13 May 2008, Jonathan Swartz wrote: > In the meantime, I might try to do this myself by creating my own > Appender subclass: > > # My::Log4perl::Appender::File defaults to my preferred layout > and layout.ConversionPattern > log4perl.appender.file1 = My::Log4perl::Appender::File > log4perl.appender.file2 = My::Log4perl::Appender::File > > Do you have a vague idea of how I might approach this? Or is it too > diffiicult, and I should just suck up the repetition until the > inheritance feature? :) Appenders and layouts are different concepts, so I wouldn't put them into the same class. I'd probably just use a template enginge like the template toolkit, define a Log4perl config file in a meta format and have the template engine expand everything before Log4perl reads in the configuration. -- Mike Mike Schilli m...@pe... |