Re: Reducing dependencies when initializing Log4perl?



On 10/03/2006 04:02 PM, robb@xxxxxxx wrote:
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?


Yes, I think so:

package MyLogWrapper;
use strict;
use warnings;
use LogForPerl; # Placeholder for Log::Log4perl

BEGIN {
LogForPerl->init('/path/to/log.conf');
}

sub get_logger {
LogForPerl->get_logger('MyPackage::MySubPackage');
}

__END__

Or you could use inheritance and override 'init' and 'get_logger.'


HTH

--
paduille.4058.mumia.w@xxxxxxxxxxxxx
Posting Guidelines for comp.lang.perl.misc:
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
.



Relevant Pages

  • Reducing dependencies when initializing Log4perl?
    ... My goal is to have zero dependencies in my source code to artifacts ... such as configuration file locations or package names. ... MyLogWrapper is the only class that knows where the config file is, ...
    (comp.lang.perl.misc)
  • Re: Purge all removed packages ?
    ... command to remove files that are part of a package but which are user editable and preserved when the main body of the package is removed. ... The port installs sample configuration files which you have to copy ... Thus the configuration file ...
    (freebsd-questions)
  • RE: [opensuse] How do I keep monitor from going to sleep
    ... install from source, etc., as opposed to say Windows, which will decide ... Isn't it really a matter of Windows not automatically installing third-party ... There really is no package manager analogy for Windows, ... can't change your configuration file automatically as it is not designed ...
    (SuSE)
  • Re: Creating configuration file failing
    ... pszItemName, Int32 cFilesToOpen, StringrgpszFilesToOpen, IntPtr hwndDlg) ... Microsoft.DataWarehouse.VsIntegration.Shell.Project.FileProjectHierarchy.Ru-nWizard(String wizardName, String newItemName) ... So I removed the existing configuration file through the provided ... wrong in this package. ...
    (microsoft.public.sqlserver.dts)
  • Re: SSIS, Excel & Package Configurations.
    ... I'm getting the 0xC020801C (cannot aquire connection) error when trying to ... You mention a configuration file, when I inherited this package, the config ... SQL2005 Database Table using OLEDB Connection Manager. ...
    (microsoft.public.sqlserver.dts)