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(@_); |
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 |
From: Aaron S. C. <as...@vi...> - 2002-10-03 13:24:02
|
On Wed, 2 Oct 2002, Kevin Goess wrote: > 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. Yes, that's reasonable. Part of my problem with the current setup is that the config mechanism will try to instantiate appenders that have nothing to do with the call to &get_logger(AppenderFoo); There is the issue of memory/processor usage but also of an appender for sending email notices causing a completely unrelated appender for logfiles to blast the last logfile, even though the logging process itself isn't being run, because the file-mode is set to 'write'. If I have a whole whack of appenders in my config shouldn't they atleast be created on an as-needed basis? I haven't had a chance to look at the code yet, but if I had to go back to the drawing board I would look at atleast *not* instantiating appenders not explictly set in the config file for : log4perl.logger.FooBar=MIN_LEVEL, A1, A2, etc. FWIW, though, the Log::Dispatch::Jabber spills its guts to Log::Dispatch::Screen (stderr) whenever it runs into a problem :-) > 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? Well, one of the attractions to log4perl is that all your logging data can be centralized. We are already subclass the main package so that the config path or data structure can be automagically specified. I can imagine adding additional checks $EUID and plugging in relevant information but I'm not wild about the idea. Anyway, we are generally pretty strict about doing things like : die "You must be root to run this program" unless ($EUID == 0); And if someone doesn't know what that means by the time they are working on root-only scripts then we probably get what we deserve. ;-) > > 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. |