From: Berg, E. <eri...@le...> - 2007-08-16 15:50:26
|
Lee, =20 I use a custom logging class that exports a get_logger(=24category) that automatically prepends the namespace hierarchy to the category passed in, so that I can always do this: =20 My logger config file looks kinda like this: =20 log4perl.logger.MyMods.Action.kgc_dir =3D DEBUG, DebugLog log4perl.logger.MyMods.Action.param =3D TRACE, DebugLog log4perl.logger.MyMods.Action.rebless =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 =3D DEBUG, DebugLog log4perl.logger.MyMods.ActionRunner.status_file_name =3D TRACE, DebugLog log4perl.logger.MyMods.Runner.Diff.run =3D TRACE, DebugLog log4perl.logger.MyMods.Runner.Diff.get_reference_action =3D DEBUG, DebugLog log4perl.logger.MyMods.Runner.Dummy.run =3D DEBUG, DebugLog log4perl.logger.MyMods.Test.get_runner =3D TRACE, DebugLog =20 Where each of the last items in the category (i.e., kgc_dir, param, rebless, etc.) are method names in my modules. =20 In each module I just do this: =20 sub my_method =7B my =24self =3D shift; my =24log =3D get_logger('my_method'); =20 =2E.. =20 =7D =20 My get_logger looks like this: =20 sub get_logger =7B my =24category =3D shift; my ( =24logger, =24log_focus, =40log_focus ); =20 =23 Initialize if we're not so already init() unless Log::Log4perl->initialized(); =20 =23 get the caller that we want. my ( =24package, =24filename, =24line, =24subroutine, =24hasargs, = =24wantarray, =24evaltext, =24is_require, =24hints, =24bitmask ) =3D caller(0); =20 =23 Put split package name into =40log_focus =40log_focus =3D split( '::', =24package ) if =24package; =20 =23 If there's a category submitted to this sub, append it to if (=24category) =7B push( =40log_focus, =24category ); =7D =20 =24log_focus =3D join( '.', =40log_focus ); =20 =24logger =3D Log::Log4perl::get_logger(=24log_focus); return =24logger; =7D =20 There's a bit more to it, but this is the essence. =20 -ERic. ________________________________ From: log4perl-devel-bounces=40lists.sourceforge.net =5Bmailto:log4perl-devel-bounces=40lists.sourceforge.net=5D On Behalf Of Lee Goddard Sent: Thursday, August 16, 2007 4:21 AM To: log4perl-devel=40lists.sourceforge.net Subject: =5Blog4perl-devel=5D Log4perl Categories Sometimes I need to just see the logging from a specific method/subroutine/function. =20 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? =20 Thanks Lee =20 Lee Goddard Senior Software Developer Advertising.com, London =20 P Think of the environment before you print this email =20 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - = - - - - - - - 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. |