From: Mike S. <m...@pe...> - 2010-01-27 09:02:49
|
On Wed, 27 Jan 2010, "Silkenbäumer, Karsten" wrote: > I found out I can use CODE refs in my config file. > log4perl.appender.testnameAppender.filename=sub { return 'example.log' > } This function doesn't get any arguments right now (warn @_) Would be > great to access the name of the logger (and maybe appender) there. Interesting idea ... I presume we could add the left side of the line as an argument to the function call, but that's probably about it. Logger info might not be available at this point. The other option is to write a subclass of Log::Log4perl::Appender::File and have it deal with the dynamically created file names. Or, you could set up your Log4perl configuration programmatically, using logger and appender methods. However, every dynamic modification comes at a price: A new person might have trouble understanding what's going on by looking at the configuration file. Leaving redundancies in place sometimes makes the configuration easier to understand. > Next thing is: using filenames, either with Dispatch::File or all the > others has one fatal behaviour: If the directory does not exists, it > throws an error message and quits. I'd be careful with that. This opens up a whole new set of problems: Are you going to create directory hierarchies of arbitrary depth? What are the permissions on each level? Rather than making the appender smarter in this regard, I'd rather modify those cronjobs to keep the directories in place. Your mileage might vary, and you might want to create a subclass of Log::Log4perl::Appender::File (rather than Log::Dispatch which misses a number of features) to accomplish what you want. Hope that helps! -- Mike Mike Schilli m...@pe... |