R
robb
Hi,
My goal is to have zero dependencies in my source code to artifacts
such as configuration file locations or package names. Usually, the
init code for Log4perl looks like this:
use Log::Log4perl;
Log::Log4perl->init("/path/to/log.conf");
my $logger = Log::Log4perl->get_logger("MyPackage::MySubPackage");
That's just way too much redundant information to put in the top of
each of my source files.
Does anyone have any other solutions? In other words, I believe one
ought to be able to do this:
use MyLogWrapper;
my $logger = MyLogWrapper->get_logger();
Two things would happen here:
1. MyLogWrapper is the only class that knows where the config file is,
and
2. It is able to determine the class/package name for when it invokes
Log4perl->get_logger.
Another option occurred to me, though for #2: I've found that if
Log4perl->get_logger() is invoked without a param, it will determine
the package of the caller. But if this invocation is in a helper class
like this, the helper class's info will be used, not the actual client.
Which made me wonder if late binding would work. In this case, my
wrapper would be used like this:
use MyLogWrapper;
my $logger = MyLogWrapper->get_logger()();
Anyone following me?
My goal is to have zero dependencies in my source code to artifacts
such as configuration file locations or package names. Usually, the
init code for Log4perl looks like this:
use Log::Log4perl;
Log::Log4perl->init("/path/to/log.conf");
my $logger = Log::Log4perl->get_logger("MyPackage::MySubPackage");
That's just way too much redundant information to put in the top of
each of my source files.
Does anyone have any other solutions? In other words, I believe one
ought to be able to do this:
use MyLogWrapper;
my $logger = MyLogWrapper->get_logger();
Two things would happen here:
1. MyLogWrapper is the only class that knows where the config file is,
and
2. It is able to determine the class/package name for when it invokes
Log4perl->get_logger.
Another option occurred to me, though for #2: I've found that if
Log4perl->get_logger() is invoked without a param, it will determine
the package of the caller. But if this invocation is in a helper class
like this, the helper class's info will be used, not the actual client.
Which made me wonder if late binding would work. In this case, my
wrapper would be used like this:
use MyLogWrapper;
my $logger = MyLogWrapper->get_logger()();
Anyone following me?