From: Aaron S. C. <as...@vi...> - 2002-10-02 13:35:16
|
[ Apologies if anyone is getting this twice; I think I sent this to the admin address by accident. ] Howdy, I'm new to these parts and still doing my homework so it's possible that I've missed something but: Is there a reason that all the appenders listed in the config data are instantiated at start-up? I ask because I came across a problem when Log4perl is used in a context where there is a single config file slurped and parsed by multiple processes with different permissions sets. Specifically, if my program is running as "joeuser" and the config file contains an appender for use by "root"-only processes to log stuff to /super/secret/logfiles via Log::Dispatch::File, the first process will always die as soon as it calls &get_logger. "joeuser" doesn't have write permissions on the logfiles directory but the File widget will try to open a handle as soon as it is created and when it fails -- I find this sort of thing a bit annoying on principle but it's not a log4perl thing -- bring the whole program down with it. This didn't seem right so I poked around a bit and tickled ::Appender.pm (see below) such that instantiation of handlers doesn't happen until the first time they are actually called. This prevents stuff like what I've described above from happening and has the added benefit of not creating a bunch of objects your program is never going to use. Left to me own devices, I might do the same thing for the actual "require"-ing of the appender classes but I'm not really sure about that one. Thoughts, comments? 60,66d59 < my $appender = $appenderclass->new( < # Set min_level to default, *we* are controlling this now < min_level => 'debug', < # Set 'name' and other parameters < map { $_ => $params{$_} } keys %params, < ); < 68,71c61,66 < appender => $appender, < name => $params{name}, < layout => undef, < level => $DEBUG, --- > appender => undef, > appenderclass => $appenderclass, > appenderparams => \%params, > name => $params{name}, > layout => undef, > level => $DEBUG, 116c111 < return $self->{appender}->log(%$p); --- > return $self->_appender()->log(%$p); 151a147,157 > sub _appender { > my $self = shift; > > if (ref($self->{appender}) ne $self->{appenderclass}) { > my $class = $self->{appenderclass}; > $self->{appender} = $class->new(min_level=>"debug",%{$self->{appenderparams}}); > } > > return $self->{appender}; > } > 161c167 < return $self->{appender}->$AUTOLOAD(@_); --- > return $self->_appender()->$AUTOLOAD(@_); |