From: Kevin G. <cp...@go...> - 2002-10-02 19:33:59
|
Interesting idea, but I have a possible objection to it. If I set up my config to log somewhere I don't have permission to write to, I would like it to tell me right now, not two days from now when fails to log that intermittent error I've been trying to catch. The principle of least surprise would seem to be on the side of an immediate failure. I understand your situation, but I wonder if there might be inherent problems in the way you're setting it up. If some other guy comes along to maintain your program, he might not know your appender is "root-only" and try to use it where he shouldn't, and be in the same boat I described above. Wouldn't it be safer having your root-only appender in some other place? Aaron Straup Cope wrote: > [ 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(@_); > > > > > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > log4perl-devel mailing list > log...@li... > https://lists.sourceforge.net/lists/listinfo/log4perl-devel -- Happy Trails . . . Kevin M. Goess (and Anne and Frank) 904 Carmel Ave. Albany, CA 94706 (510) 525-5217 |