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... |