From: Lee G. <LGo...@UK...> - 2007-08-17 07:36:27
|
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:eri...@le...]=20 Sent: 16 August 2007 16:49 To: Lee Goddard; log...@li... Subject: RE: [log4perl-devel] Log4perl Categories Lee, =A0 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: =A0 My logger config file looks kinda like this: =A0 log4perl.logger.MyMods.Action.kgc_dir=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D = DEBUG, DebugLog log4perl.logger.MyMods.Action.param=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =3D = TRACE, DebugLog log4perl.logger.MyMods.Action.rebless=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=3D = TRACE, DebugLog log4perl.logger.MyMods.ActionRunner.get_status =3D DEBUG, DebugLog log4perl.logger.MyMods.ActionRunner.get_status_from_file =3D TRACE, = DebugLog log4perl.logger.MyMods.ActionRunner.run=A0=A0=A0=A0=A0=A0=A0 =3D DEBUG, = DebugLog log4perl.logger.MyMods.ActionRunner.status_file_name =3D TRACE, DebugLog log4perl.logger.MyMods.Runner.Diff.run=A0=A0=A0=A0=A0=A0=A0=A0=A0=3D = TRACE, DebugLog log4perl.logger.MyMods.Runner.Diff.get_reference_action =3D DEBUG, = DebugLog log4perl.logger.MyMods.Runner.Dummy.run=A0=A0=A0=A0=A0=A0=A0 =3D DEBUG, = DebugLog log4perl.logger.MyMods.Test.get_runner=A0=A0=A0=A0=A0=A0=A0=A0 =3D = TRACE, DebugLog =A0 Where each of the last items in the category (i.e., kgc_dir, param, = rebless, etc.) are method names in my modules. =A0 In each module I just do this: =A0 sub my_method { =A0=A0=A0 my $self =3D shift; =A0=A0=A0 my $log =3D get_logger('my_method'); =A0 ... =A0 } =A0 My get_logger looks like this: =A0 sub get_logger { =A0=A0=A0 my $category =3D shift; =A0=A0=A0 my ( $logger, $log_focus, @log_focus ); =A0 =A0=A0=A0 # Initialize if we're not so already =A0=A0=A0 init() unless Log::Log4perl->initialized(); =A0 =A0=A0=A0 # get the caller that we want. =A0=A0=A0 my ( $package, $filename, $line, $subroutine, $hasargs, = $wantarray, $evaltext, $is_require, $hints, $bitmask ) =3D caller(0); =A0 =A0=A0=A0 # Put split package name into=A0 @log_focus =A0=A0=A0 @log_focus =3D split( '::', $package ) if $package; =A0 =A0=A0=A0 # If there's a category submitted to this sub, append it to =A0=A0=A0 if ($category) { =A0=A0=A0=A0=A0=A0=A0 push( @log_focus, $category ); =A0=A0=A0 } =A0 =A0=A0=A0 $log_focus =3D join( '.', @log_focus ); =A0 =A0=A0=A0 $logger =3D Log::Log4perl::get_logger($log_focus); =A0=A0=A0 return $logger; } =A0 There's a bit more to it, but this is the essence. =A0 -ERic. ________________________________________ From: log...@li... = [mailto:log...@li...] On Behalf Of Lee = Goddard Sent: Thursday, August 16, 2007 4:21 AM To: log...@li... 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.=A0 Would it be a bad = idea to incorporate this? Thanks Lee |