From: <msc...@ao...> - 2002-09-24 03:16:02
|
In a message dated Mon, 23 Sep 2002 8:59:31 PM Eastern Standard Time, mrd...@ya... writes: >Couldn't the interface be simpler? > use Log::Log4perl::EZ; > ... > DEBUG("New food: $what"); # Or Debug() or debug() Funny, a couple of weeks ago I had exactly that in there. However, there was some resistance on log4perl-devel (Kevin!!!:) arguing that we need to educate people to explicitely state the category (which could be very different from the package name BTW). The other argument against the 'EZ' interface was that something like DEBUG("Something happened!!!"); # ... DEBUG("Something else!!!"); needs to call get_logger() twice behind the scenes, which is un peu slower than my $logger = get_logger("Blah::Poo"); $logger->debug("Something happened!!!"); # ... $logger->debug("Something else!!!"); which just obtains the logger instance once. Which could have a significant impact if there are 20 debug statements within one function. I guess there's always a tradeoff -- but if one more person asks for it, I'll hammer it in, you've been warned :). -- -- Mike ############################ # Mike Schilli # # log...@pe... # # http://perlmeister.com # # log4perl.sourceforge.net # ############################ |
From: <msc...@ao...> - 2002-09-24 04:45:59
|
In a message dated Mon, 23 Sep 2002 11:05:31 PM Eastern Standard Time, mrd...@ya... writes: >A quick glance at the code, and me think one could cache >the logger objects without trouble (unless they are much >bigger than I think). So get_logger would become: Well, this is already done of course by the current implementation -- Log4perl uses a singleton mechanism. The overhead arises because of multiple get_logger() calls (which are admittedly quite cheap, but it adds up). -- -- Mike ############################ # Mike Schilli # # log...@pe... # # http://perlmeister.com # # log4perl.sourceforge.net # ############################ |
From: Erik W. S. <er...@se...> - 2002-09-24 05:32:29
|
Well, what I actually did in my code is something that looks a lot like this. :) I basically created a faux package that exports $logger into the current namespace. So yeah, it's basically a global variable. But sometimes, that's what you want. :) Anyway, I then just call $logger->whatever() whenever and whereever I want, and never really worry about it. Oh and I don't use categories, as mostly what I'm doing is outputting to a given file or syslog. Just me. If I'm good I'll rip out all the Real-specific things and post it. -e msc...@ao... wrote: >In a message dated Mon, 23 Sep 2002 11:05:31 PM Eastern Standard Time, mrd...@ya... writes: > > > >>A quick glance at the code, and me think one could cache >>the logger objects without trouble (unless they are much >>bigger than I think). So get_logger would become: >> >> > >Well, this is already done of course by the current implementation -- Log4perl uses a singleton mechanism. > >The overhead arises because of multiple get_logger() calls (which are admittedly quite cheap, but it adds up). > > > |
From: Mathieu L. <mrd...@ya...> - 2002-09-24 04:05:31
|
--- msc...@ao... wrote: > Funny, a couple of weeks ago I had exactly that in there. > However, there was some resistance on log4perl-devel > (Kevin!!!:) arguing that we need to educate people to > explicitely state the category (which could be very > different from the package name BTW). Hum. Sure. Programmers tend to be lazy, if they have to go through this trouble to write logging calls, you end up with no logging... And then, what do you turn on to debug your system at runtime? You still have the option of changing the category name. Maybe you could do it at the use level: use Log::Log4perl::EZ +MyOwnCategory; (Note that I'm not positive how to implement this, I'm just throwing the suggestion). > my $logger = get_logger("Blah::Poo"); > $logger->debug("Something happened!!!"); > # ... > $logger->debug("Something else!!!"); > > which just obtains the logger instance once. Which could > have a significant impact if there are 20 debug > statements within one function. A quick glance at the code, and me think one could cache the logger objects without trouble (unless they are much bigger than I think). So get_logger would become: sub get_logger() { ... my $category = $_[0]; return $loggers{$category} if exists $loggers{$category}; return $loggers{$category} = Log::Log4perl::Logger->get_logger($category); } What do you think? -Mathieu __________________________________________________ Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! http://sbc.yahoo.com |