Thanks for the help! If anyone else is interested, I merged the data using Hash::Merge, and it seems to have the behaviour I was looking for. Pretty concise too.
use Data::Dumper; use Hash::Merge qw( merge ); use Log::Log4perl::Config; use Log::Log4perl::Config::PropertyConfigurator; my $user_conf = Log::Log4perl::Config::PropertyConfigurator->new(); $user_conf->file("s4:[bhumphreys.cube.exg.kosdaq]log.conf"); my $user_data = $user_conf->parse(); # will die() on error print Dumper($user_data); my $def_conf = Log::Log4perl::Config::PropertyConfigurator->new(); $def_conf->file("s4:[bhumphreys.cube_dev.lib]default_logger.conf"); my $defaults = $def_conf->parse(); # will die() on error print Dumper($defaults); Hash::Merge::set_behavior( 'LEFT_PRECEDENT' ); my %results = %{ merge( $user_data, $defaults ) }; print Dumper(\%results); From: Mike Schilli <m...@perlmeister.com> To: Ben Humphreys <bhumphr...@factset.com> Cc: log4perl-devel@lists.sourceforge.net Date: 01/04/2009 01:41 Subject: Re: [log4perl-devel] Multiple Config Files, or Default Behaviour Workarounds? On Tue, 31 Mar 2009, Ben Humphreys wrote: > I want a default base set up for the logs, for formatting and levels > of explicit-ness, but I also want users to be able to override certain > parts of this behaviour with config files. > I can imagine doing the default behaviour in Perl, and then loading the > config file, but I'm not sure if that will trash all the default settings. > Or there is the string merge idea from the link above, but that seems a > little tricky. If you want to make sure that your settings have precedence, you need to load the user configuration file first and then make the corrections. The other way around, their configuration will override yours. One way to 'merge' two configurations to use the parse() method of the Log::Log4perl::Config::PropertyConfigurator class: use Data::Dump qw(dump); use Log::Log4perl::Config; use Log::Log4perl::Config::PropertyConfigurator; my $conf = Log::Log4perl::Config::PropertyConfigurator->new(); $conf->file("l4p.conf"); my $data = $conf->parse(); # will die() on error print dump($data); After that (and note that parse() will die() if there's an error, so you might want to use an eval {} around it), $data will contain a data structure that you then can modify and merge with another one obtained from a second file. Once you have a satisfactory data structure in $data, you can pass it as the second (!) argument to Log4perl's init function: Log::Log4perl->init( undef, $data ); Highly undocumented feature ;). Hope that helps! -- Mike Mike Schilli m...@perlmeister.com
------------------------------------------------------------------------------
_______________________________________________ log4perl-devel mailing list log4perl-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/log4perl-devel