in reply to Wrapper class for log4perl redirects to wrong log file
It looks like you are trying to setup an instance of Log::Log4perl up as a singleton (you are using my $log in the global scope of the module). Why bother with this when Log4perl already does this for you?
I would probably forgo the creation of an object, and just provide a class function in your module that gets a Log4perl object and initializes it first if it isn't already initialized. Something like this:
package MyLogger; # Wrapper class for Log::Log4perl. use strict; use warnings; use Log::Log4perl; sub get_logger { # initialize and return MyLogger object my $class = shift; my $module_name = shift; unless (Log::Log4perl->initialized) { Log::Log4perl->init("/opt/etc/log4perl.conf"); $Log::Log4perl::caller_depth = 1; } return Log::Log4perl->get_logger($module_name); }
Then in your code you get to use the actual Log::Log4perl object and you won't have to write helper functions like 'debug' and such. It is still efficient, since Log::Log4perl is a singleton. Here is how you could use it:
my $log = MyLogger->get_logger('database'); $log->debug('database blah blah'); $log = MyLogger->get_logger('apache'); $log->debug('apache blah blah');
The above code is untested, but it should work...
-Cees
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Wrapper class for log4perl redirects to wrong log file
by andreas1234567 (Vicar) on Feb 09, 2004 at 17:13 UTC |