From: Bart P. <ba...@la...> - 2004-12-09 20:00:40
|
Basically I have a process that logs to a master log file, the screen and email, that I've converting from Log::Dispatch to Log::Log4perl -- and this part works great. I need to add the ability of periodically opening/closing log files in other directories (e.g. like daily logs) where the directories do not necessarily exist when the process (and Log4perl) initializes. (Similar to Log::Dispatch's add and remove methods). Obviously I can use add_appender to open a new log file, but I'm not sure how to remove the appender when I'm finished with it. I couldn't find anything like "remove_appender" though perhaps I'm just missing it. The FAQ seems to indicate that the way to turn off logging is to set the threshold to OFF. Unfortunately, over time, this will leak appenders. Is there a clean way to remove appenders at runtime? Thanks, Bart Parliman |
From: Kevin M. G. <ke...@go...> - 2004-12-13 06:56:04
|
> Is there a clean way to remove appenders at runtime? Not currently, that I know of anyway. An alternate solution you might consider if you're in a unix-y environment is the creative use of symlinks, something like this ln -s 2004-12-11/ todayslogs Would allow you to todayslogs/logfile.log and not have to change it at runtime. -- Happy Trails . . . Kevin M. Goess (and Anne and Frank) 904 Carmel Ave. Albany, CA 94706 (510) 525-5217 |
From: Mike S. <m...@pe...> - 2004-12-14 19:45:11
|
On Sun, 12 Dec 2004, Kevin M. Goess wrote: > > Is there a clean way to remove appenders at runtime? > Not currently, that I know of anyway. Nope, looks like we need to add one. For now, could you use Log::Log4perl::Appender::File's file_switch() method instead? -- Mike Mike Schilli m...@pe... |
From: Bart P. <ba...@la...> - 2004-12-15 16:51:23
|
On Tue, 14 Dec 2004, Mike Schilli wrote: > On Sun, 12 Dec 2004, Kevin M. Goess wrote: > >>> Is there a clean way to remove appenders at runtime? > >> Not currently, that I know of anyway. > > Nope, looks like we need to add one. That would be great. > For now, could you use Log::Log4perl::Appender::File's file_switch() > method instead? For the short term this is fine. I'm actually reusing my own subclass under Log::Dispatch::Output(?) so I could add something similar there. The main issue is that I may have multiple log files files that need to be opened at the same time (i.e. so it's not exactly like a log file that is periodically switched). Thanks, Bart |
From: Mike S. <m...@pe...> - 2004-12-15 19:32:45
|
On Wed, 15 Dec 2004, Bart Parliman wrote: > For the short term this is fine. I'm actually reusing my own > subclass under Log::Dispatch::Output(?) so I could add something > similar there. The main issue is that I may have multiple log > files files that need to be opened at the same time (i.e. so it's > not exactly like a log file that is periodically switched). Not sure if I fully understand the requirements ... isn't it good enough to open them all at startup (or L4p init time)? In any case, I've added remove_appender() yesterday, see the latest tarball: http://www.perlmeister.com/tmp/Log-Log4perl-0.51.tar.gz There's also a paragraph of documentation within the main Log4perl docs on it, especially what to do for appender cleanup. Let me know if it works for you ... -- Mike Mike Schilli m...@pe... |
From: Mike S. <m...@pe...> - 2004-12-16 07:01:57
|
On Wed, 15 Dec 2004, Bart Parliman wrote: > The files are periodically opened throughout a long running > process and it is not known ahead of time where they will be > located or what they will be called. Basically the process > looks like this ... > > daemon starts > init L4p (setup master logfile) > ... > work named "foo" comes in > create a "foo" work directory > open "foo" logfile in that directory > do work in new directory (generate reports, etc.) > close work event logfile > tar up directory > archive it off somewhere > ... > work named "bar" comes in > create a "bar" work directory > (repeat) > ... Ok, gotcha. Another way to accomplish this would have been a custom appender that a) creates new files on demand (i.e. upon log(), not new()) b) uses something like the MDC as described in http://log4perl.sourceforge.net/d/Log/Log4perl.html#4b5b3 to determine the current file name > In the future multiple work events may occur in parallel. Dicey! Then you have to set the MDC with every logging call. How do you solve that with dynamically created appenders? > This logs properly, but the appender's DESTROY method is not > called until the process terminates, even if I destroy the > appender in my code (e.g. with undef, or it goes out of scope). > Since the file is closed when the appender goes away, it will > remain open. > > It looks like there is a reference to the appender in the > Log::Log4perl::Logger::APPENDER_BY_NAME hash. Just as a test, I > noticed that if I delete that entry by hand after undef'ing the > appender, the appender is destroyed as well. Ah, good one. The problem is that remove_appender() removes an appender from a logger, but it could still be used by other loggers. And even if not, you could have an appender in your conf file which no one uses, but it's still in the system, waiting for someone to call add_appender(). So L4p can't forget about the appender just because it gets removed from one logger or even all loggers. So, I've added another call, eradicate_appender(), which can be called either as L4p->eradicate_appender($name) or $logger->eradicate_appender($name), which will do what you like: To eradicate an appender from the system, you need to call C<Log::Log4perl-E<gt>eradicate_appender($appender_name)> which will first remove the appender from every logger in the system and then will delete all references Log4perl holds to it. Docs and test cases have been updated. > Also a couple of minor issues with the new documentation... Fixed, thanks! > Besides a minor formatting issue, the user probably shouldn't > call the appender's DESTROY method to get rid of it (since perl > does that internally), but merely undef it instead. By all means, what was I thinking :). I've fixed it, thanks for pointing this out! New tarball on http://www.perlmeister.com/tmp/Log-Log4perl-0.51.tar.gz -- Mike Mike Schilli m...@pe... |
From: Bart P. <ba...@la...> - 2004-12-16 16:27:12
|
Mike On Wed, 15 Dec 2004, Mike Schilli wrote: > Docs and test cases have been updated. Now that you've quickly completed all of this free work for me, I have a little project I'd like you to look at... :-) Thanks for all of your help, Bart |