Thanks, Mike. Extremely helpful. I've never used caller for anything but endeavors of curiosity. I've read that document before, but...
Here's what I quickly came up with: sub get_logger { ... # get the caller that we want. @caller = caller(1); $package = $caller[0]; @log_focus = split( '::', $package ); # If there's a category submitted to this sub, append it to @log_focus if ($category) { push( @log_focus, $category ) } $log_focus = join( '.', @log_focus ); $logger = Log::Log4perl::get_logger($log_focus); return $logger; } Obviously, this is a much better way to do this. I guess a short recursive subroutine which uses caller could tell you in which package a function is defined. And that's how carp works, huh? Pretty cool. Thank you very much. -Eric -----Original Message----- From: Mike Schilli [mailto:[EMAIL PROTECTED] Sent: Thursday, June 28, 2007 8:45 PM To: Berg, Eric Cc: Mike Schilli; log4perl-devel@lists.sourceforge.net Subject: RE: [log4perl-devel] When a missing config file On Thu, 28 Jun 2007, Berg, Eric wrote: > Are there any best practices, examples, etc. for the best way to > provide a wrapper to log? Here's a couple of hints: http://log4perl.sourceforge.net/d/Log/Log4perl.html#6acb7 > I'm using some of the sample code that provides a _get_logger() > function that derives the category based on the package from which > it's called Isn't that already provided by __PACKAGE__? > , but I've created a problem for myself when it's in an inherited > class in a subclass called in a subclass -- my wrapper is set up to > provide _get_logger() as an inherited method -- because if I define a > method in a superclass, and it's called in a subclass, then I can't > just enable logging for the method in the superclass, because it's the > package name of the subclass from which the category is derived. Hmm, any reason why you aren't simply using Log4perl's get_logger()? > So, to reiterate, I have a class hierarchy, and the top-level class is > the one that does a > > use base qw(My::Logger); > > Then, when one of my subclasses calls _get_logger(), it creates a > logger with the category of the subclass, whereas at least sometimes I > want to enable logging for that inherited method whenever it's called. Just to clarify: Is this your application or your logger class hierarchy? If the former, it shouldn't be a subclass of Logger. If the latter, you probably want to use L4p's get_logger() and pass it the category you want. > Another solution would be wildcard/regex categories. Can we do that? What's the problem you're trying to solve there? -- Mike Mike Schilli [EMAIL PROTECTED] > > Thanks! > > -Eric. > > -----Original Message----- > From: Mike Schilli [mailto:[EMAIL PROTECTED] > Sent: Thursday, June 28, 2007 7:54 PM > To: Berg, Eric > Cc: log4perl-devel@lists.sourceforge.net > Subject: Re: [log4perl-devel] When a missing config file > > On Thu, 28 Jun 2007, Berg, Eric wrote: > > > I've been looking for a way to get l4p to tell me where the config > > under which it's running comes from. Essentially, I'd like to have > > a method that would return the full path to the config file that > > it's currently using. > > > > Obviously, there are complications, such as those relating to > > programatic configuration subsequent to loading configs from a file, > > in-line, and config (ini) files, but I could find nowhere that the > > file name passed in to init() is retrievable. > > The name of the file isn't stored usually, since you can not only use > a file but a string, a hashref, an URL, etc. to initialize L4p. > > Since you're calling init() in the first place, wouldn't it be easier > to store the filename in your application instead? > > -- Mike > > Mike Schilli > [EMAIL PROTECTED] > > > > > -Eric. > > > > -----Original Message----- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On Behalf Of > > John ORourke > > Sent: Thursday, June 28, 2007 6:42 AM > > To: Lee Goddard > > Cc: log4perl-devel@lists.sourceforge.net > > Subject: Re: [log4perl-devel] When a missing config file > > > > Try putting: > > > > use Error; > > > > in one of your modules/scripts - it will override the warn/die > > handlers globally, so unless Log4perl overrides them again it will > > give you a stack trace. > > > > cheers > > John > > > > Lee Goddard wrote: > > > > > > Please could Log/Log4perl/Config.pm line 619 offer a stack > > > backtrace > > > > as well as barfing? > > > > > > My current project has four config files, several potential > > > initialisers (bad idea, I know) and reports only via e-mail, since > > > it is part of a MTA process. > > > > > > Thanks in anticipation > > > > > > Lee > > > > > > > > > > > > > > > > > > # The Postfix program > > > > > > # > > > > > > # <[EMAIL PROTECTED]>: Command died with status 2: > > > "perl > > > > > > # -I/home/lgoddard/trafficjam/trunk/lib > > > -MTrafficJam::Controller::Root -e > > > > > > # 'warn TrafficJam::Controller::Root->mail_in'". Command output: > > > Cannot open > > > > > > # config file '/home/lgoddard/trafficjam/trunk/config/mail.l4p' > at > > > > > > # /usr/local/share/perl/5.8.4/Log/Log4perl/Config.pm line 619, > > > <STDIN> line > > > > > > # 26. > > > > > > # > > > > > > > > > > > > Lee Goddard > > > > > > Senior Software Developer > > > > > > Advertising.com, London > > > > > > > > > > > > P Think of the environment before you print this email > > > > > > > > > > > > ------------------------------------------------------------------ > > > -- > > > -- > > > -- > > > > > > ------------------------------------------------------------------ > > > -- > > > -- > > > --- This SF.net email is sponsored by DB2 Express Download DB2 > > > Express > > > > > C - the FREE version of DB2 express and take control of your XML. > > > No > > > > limits. Just data. Click to get it now. > > > http://sourceforge.net/powerbar/db2/ > > > ------------------------------------------------------------------ > > > -- > > > -- > > > -- > > > > > > _______________________________________________ > > > log4perl-devel mailing list > > > log4perl-devel@lists.sourceforge.net > > > https://lists.sourceforge.net/lists/listinfo/log4perl-devel > > > > > > > > > -------------------------------------------------------------------- > > -- > > -- > > - > > This SF.net email is sponsored by DB2 Express Download DB2 Express C > > - > > > the FREE version of DB2 express and take control of your XML. No > limits. > > Just data. Click to get it now. > > http://sourceforge.net/powerbar/db2/ > > _______________________________________________ > > log4perl-devel mailing list > > log4perl-devel@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/log4perl-devel > > > > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > > - > > - - - - - - - - - > > > > 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 DB2 Express Download DB2 > > Express > > > C - the FREE version of DB2 express and take control of your XML. No > > limits. Just data. Click to get it now. > > http://sourceforge.net/powerbar/db2/ > > _______________________________________________ > > log4perl-devel mailing list > > log4perl-devel@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/log4perl-devel > > > > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > - - - - - - - - - > > 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 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 DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ log4perl-devel mailing list log4perl-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/log4perl-devel