horrendo has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I'm obviously missing something here. My log4perl.conf file looks like this :

# # Loggers # log4perl.logger.B2B::Display =ERROR, B2B_FILE log4perl.logger.B2B::Bin =TRACE, BIN_FILE, BIN_STDERR, BIN_STDO +UT # # Appenders # log4perl.appender.B2B_FILE=Log::Dispatch::File log4perl.appender.B2B_FILE.filename=/project/myproj/log/cgi/cgi.log log4perl.appender.B2B_FILE.autoflush=1 log4perl.appender.B2B_FILE.syswrite=1 log4perl.appender.B2B_FILE.utf8=1 log4perl.appender.B2B_FILE.umask=002 log4perl.appender.B2B_FILE.group=www-data log4perl.appender.B2B_FILE.mode=append log4perl.appender.B2B_FILE.min_level=debug log4perl.appender.B2B_FILE.layout=PatternLayout log4perl.appender.B2B_FILE.layout.ConversionPattern=[%P]%d{yyyyMMdd HH +:mm:ss.SSS}|%M|%L|%m%n log4perl.appender.BIN_FILE=Log::Dispatch::File log4perl.appender.BIN_FILE.filename=/project/myproj/log/bin/bin.log log4perl.appender.BIN_FILE.autoflush=1 log4perl.appender.BIN_FILE.syswrite=1 log4perl.appender.BIN_FILE.utf8=1 log4perl.appender.BIN_FILE.umask=002 log4perl.appender.BIN_FILE.group=myprojgroup log4perl.appender.BIN_FILE.mode=append log4perl.appender.BIN_FILE.min_level=error log4perl.appender.BIN_FILE.layout=PatternLayout log4perl.appender.BIN_FILE.layout.ConversionPattern=[%P]%d{yyyyMMdd HH +:mm:ss.SSS}|%M|%L|%m%n log4perl.appender.BIN_STDERR=Log::Dispatch::Screen log4perl.appender.BIN_STDERR.stderr=1 log4perl.appender.BIN_STDERR.min_level=error log4perl.appender.BIN_STDERR.layout=PatternLayout log4perl.appender.BIN_STDERR.layout.ConversionPattern=[%P]%d{yyyyMMdd +HH:mm:ss.SSS}|%M|%L|%m%n log4perl.appender.BIN_STDOUT=Log::Dispatch::Screen log4perl.appender.BIN_STDOUT.stderr=0 log4perl.appender.BIN_STDOUT.max_level=warning log4perl.appender.BIN_STDOUT.layout=PatternLayout log4perl.appender.BIN_STDOUT.layout.ConversionPattern=[%P]%d{yyyyMMdd +HH:mm:ss.SSS}|%M|%L|%m%n

I have two different class hierarchies - Display::xxx and Bin:xxx. The Display::xxx classes are instantiated by apache (www-data) and the Bin:xxx classes are instantiated by user 'x'.

The www-data and x users do not share a common group.

The problem I have is that when I create a logger for a Bin::xxx class, it tries to create the cgi.log file - even though it is only referenced by the B2B_FILE appender that Bin::xxx classes do not reference.

If user 'x' does have write access to the cgi directory, creating a logger for a Bin::xxx class does create an empty cgi.log file. If user 'x' does *not* have write access, I get a runtime permissions error saying it cannot write to .../cgi/cgi.log - even though I don't want it to.

Do I need to have separate config files for the two different types of classes?

Thanks for your help (and patience).

H.

20100504 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: Question on Log4perl config file
by andreas1234567 (Vicar) on May 04, 2010 at 11:46 UTC
Re: Question on Log4perl config file
by kgoess (Beadle) on May 04, 2010 at 18:11 UTC

    Yeah, Log4perl opens the files for every file appender when it starts up. Otherwise it might not find out there's a problem writing to the log file until it tries to log some important error message, only to find that it can't.

    If you're on a unixy ooperating system, this would be the route I'd try:

    http://en.wikipedia.org/wiki/Setuid#setgid_on_directories