From: Duncan C. <dca...@bc...> - 2002-12-05 19:21:13
|
On 2002-12-03 Mike Schilli <msc...@ao...> wrote: >Hi there, > >Kai Poitschke has brought up an interestingfeature request: Suppose, >your application had a configuration "-l logfilename" option to specify >the name of the log file to be used. Now, if you have an external >configuration file (as opposed to a string ref passed to init()), how >would you be able to adapt the config file setting in the code? > >He suggests to have init() overwrite certain properties of the config >file like in: > > Dump2OWH.conf: > >log4perl.category.Dump2OWH = INFO, File, Screen > >log4perl.appender.File = Log::Dispatch::File >log4perl.appender.File.filename = Dump2OWH.log >log4perl.appender.File.mode = write >log4perl.appender.File.layout = Log::Log4perl::Layout::PatternLayout >log4perl.appender.File.layout.ConversionPattern = %d: %m%n > >log4perl.appender.Screen = Log::Dispatch::Screen >log4perl.appender.Screen.stderr = 0 >log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout >log4perl.appender.Screen.layout.ConversionPattern = %-5p> %m%n > > >test.pl: > # Einstellungen z.B. aus Programmflags bestimmt > $more_conf = q(log4perl.appender.File.filename = test.log > log4perl.appender.File.mode = append); > > Log::Log4perl::init('Dump2OWH.conf', $more_conf); > > >I can see at least one other way to implement it: a >not-yet-implemented-in-Log4perl feature like variables in config files >(log4j has something like that but I don't think they can specify the >variable replacement values via code) and a mechanism to define the >placeholders in init(conf_file, key => value, key => value); > >Any other ideas? Sounds like a pretty useful feature to me. > Initially I wondered why I couldn't do something like this: Log::Log4perl::init('Dump2OWH.conf'); my $appender = get_appender('File'); $appender->filename('test.log'); but after investigating found that get_appender is part of the log4j API which hasn't been implemented, Log::Dispatch::File doesn't support get and set methods on its instance variables, and, more importantly, that the output file is opened as part of the creation of the appender during the init(), so it's then too late to change the file name. Regards, Duncan Cameron |