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
Lee Goddard
Senior Software Developer
Advertising.com, London
P Think of the environment before you print this email
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
This message is intended only for the personal and confidential use of the
designated recipient(s) named above. If you are not the intended recipient of
this message you are hereby notified that any review, dissemination,
distribution or copying of this message is strictly prohibited. This
communication is for information purposes only and should not be regarded as an
offer to sell or as a solicitation of an offer to buy any financial product, an
official confirmation of any transaction, or as an official statement of Lehman
Brothers. Email transmission cannot be guaranteed to be secure or error-free.
Therefore, we do not represent that this information is complete or accurate
and it should not be relied upon as such. All information is subject to change
without notice.
--------
IRS Circular 230 Disclosure:
Please be advised that any discussion of U.S. tax matters contained within this
communication (including any attachments) is not intended or written to be used
and cannot be used for the purpose of (i) avoiding U.S. tax related penalties
or (ii) promoting, marketing or recommending to another party any transaction
or matter addressed herein.
-------------------------------------------------------------------------
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