Thanks, Eric - that made sense, and the config is as I imagined.

I'm really into the ':easy' way, though, despite the OO nature of most of my 
modules, so I'll have to start sub-classing, I think.

Thanks again
Lee

________________________________________
From: Berg, Eric [mailto:[EMAIL PROTECTED] 
Sent: 16 August 2007 16:49
To: Lee Goddard; log4perl-devel@lists.sourceforge.net
Subject: RE: [log4perl-devel] Log4perl Categories

Lee,
 
I use a custom logging class that exports a get_logger($category) that 
automatically prepends the namespace hierarchy to the category passed in, so 
that I can always do this:
 
My logger config file looks kinda like this:
 
log4perl.logger.MyMods.Action.kgc_dir          = DEBUG, DebugLog
log4perl.logger.MyMods.Action.param            = TRACE, DebugLog
log4perl.logger.MyMods.Action.rebless          = TRACE, DebugLog
log4perl.logger.MyMods.ActionRunner.get_status = DEBUG, DebugLog
log4perl.logger.MyMods.ActionRunner.get_status_from_file = TRACE, DebugLog
log4perl.logger.MyMods.ActionRunner.run        = DEBUG, DebugLog
log4perl.logger.MyMods.ActionRunner.status_file_name = TRACE, DebugLog
log4perl.logger.MyMods.Runner.Diff.run         = TRACE, DebugLog
log4perl.logger.MyMods.Runner.Diff.get_reference_action = DEBUG, DebugLog
log4perl.logger.MyMods.Runner.Dummy.run        = DEBUG, DebugLog
log4perl.logger.MyMods.Test.get_runner         = TRACE, DebugLog
 
Where each of the last items in the category (i.e., kgc_dir, param, rebless, 
etc.) are method names in my modules.
 
In each module I just do this:
 
sub my_method {
    my $self = shift;
    my $log = get_logger('my_method');
 
...
 
}
 
My get_logger looks like this:
 
sub get_logger {
    my $category = shift;
    my ( $logger, $log_focus, @log_focus );
 
    # Initialize if we're not so already
    init() unless Log::Log4perl->initialized();
 
    # get the caller that we want.
    my ( $package, $filename, $line, $subroutine, $hasargs, $wantarray, 
$evaltext, $is_require, $hints, $bitmask ) = caller(0);
 
    # Put split package name into  @log_focus
    @log_focus = split( '::', $package ) if $package;
 
    # If there's a category submitted to this sub, append it to
    if ($category) {
        push( @log_focus, $category );
    }
 
    $log_focus = join( '.', @log_focus );
 
    $logger = Log::Log4perl::get_logger($log_focus);
    return $logger;
}
 
There's a bit more to it, but this is the essence.
 
-ERic.

________________________________________
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Lee Goddard
Sent: Thursday, August 16, 2007 4:21 AM
To: log4perl-devel@lists.sourceforge.net
Subject: [log4perl-devel] Log4perl Categories
Sometimes I need to just see the logging from a specific 
method/subroutine/function.

I realize I can change the log levels within that block of code, but it would 
be convenient to be able to say log4perl.category.bar.twix.eat to just see the 
logging from Bar::Twix's 'eat' method.  Would it be a bad idea to incorporate 
this?

Thanks
Lee


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel

Reply via email to