Re: [Pas-dev] Suggestion for logging
Status: Beta
Brought to you by:
mortis
From: Mental P. <me...@ne...> - 2003-06-13 14:32:39
|
On Thu, 2003-06-12 at 19:05, Kyle R. Burton wrote: > In the Java projects I've been involved with, we've used Jakarta's > Log4j. Probably the most important features of the logging library are > that you can tweak the logging level or the destination(s) from a > configuration file. >=20 I'm familiar, if not well versed, with how it works. Its a pretty cool idea. > ### > package Org::Bgw::Log; > ... > use Log::Log4perl; > Log::Log4perl->init($ENV{'PAS_BASE'}."/conf/log4perl.conf"); > # get a Log4perl log object based on the caller's package name > sub getLogger { Log::Log4perl::get_logger( (caller)[0] ); } >=20 >=20 > Then in any random module: >=20 > ### > package Org::Bgw::Foo; > ... > my $log =3D Org::Bgw::Log::getLogger; >=20 > sub somethingComplicated > { > my($self) =3D @_; >=20 > # testing log->is_debug is an optimization so that Dumper isn't > # called (since it could be expensive) unless the log level is set > # to debug -- unless the level is debug, the arguments aren't > # computed, and the log statement isn't called. > if( $log->is_debug() ) { > $log->debug("somethingComplicated, self =3D ", Dumper($self) ); > } I like everything except the if $log->is_debug. I haven't looked into or spent more than 2 seconds thinking about implementation, but wouldn't it be easier if you just wrapped it (log4perl) with Org::Bgw::Log? Then you could just call $self->log()->debug like usual. Let the wrapper do the debug level check and just return if its not set. IF it is set, it can call its getLogger method and log stuff. It'll be better separation between page objects and log levels. It'll avoid needless instantiations of the lob ogject and simplify the interface. Know what i mean?=20 That and depending on the names of the log levels it'd be a transparent change. The only differences would be config file stuff and suddenly you can log on a per-package basis.=20 Hopefully this is coherent.....=20 --=20 Mental (Me...@Ne...) Distant - An approaching age When this document falls beneath another's gaze Too late - We have lost the dawn The signal's loud and clear, but the transmitter's gone --Assemblage 23 "Document" |