From: Jim C. <jc...@di...> - 2003-04-17 23:13:33
|
attached tarball has logger/* Im proposing that it become part of the family - ie gets a little piece of the namespace, since its so dependent on the family resources.=20 so, without further ado, heres part of the pod. NAME Log::Log4perl::AutoCat - a simple Log4perl wrapper with some cool features DESCRIPTION This is a wrapper class that uses the some of the really cool Log::Log4perl features in corrupt an lazy ways; AutoCategorization normal use of Log4perl requires that you define a hierar=AD chy of logging categories, and code them into your classes. Because the logging category is orthogonal to severity, and because your categories are essentially unbounded, you can get detailed control over the logging done by your application. But (you knew this was coming), if youre lazy like me, you dont want the drudgery of coming up with lots of cate=AD gories, and making sure theyre consistent. You note that your class hierarchy could serve as a logging category. NOW IT CAN. This package constructs such a $logcat dynamically, using the package name, subroutine name, and line number. Sim=AD plifying somewhat, the code does: 1. uses caller() to construct a category string dynamically. 2. fetches the $logger singleton {$logger =3D get_logger($logc= at)} 3. tests if $logcat was a loggable event {$logger->is_$logcat(= )} 4. record the invocation. 5. do the Log4perl call if 3 tests true Step 4 is done just because its informative; all invoca=AD tions are cataloged in %seenCat, and this can serve as a good 1st estimate of test coverage of your application code. This coverage is summarized at END time; (15:24:24.772) Logger.END.info.106: $Seen Log Events: =3D [ { 'GenWidget.new.debug.34' =3D> 61, 'GenWidget.new.error.96' =3D> 5, 'GwApi.exit.error.328' =3D> 1, 'GwConf.read_file.info.137' =3D> 12, 'Logger.END.info.106' =3D> 1, 'Widget.Match.debug.225' =3D> 61, 'Widget.Match.debug.240' =3D> 61, 'Widget.Match.debug.257' =3D> 1, 'Widget.Match.debug.263' =3D> 543, 'Widget.Match.debug.272' =3D> 55, 'Widget.Match.error.280' =3D> 5, 'Widget.import.info.85' =3D> 1, 'Widget.loadWidgets.debug.118' =3D> 13, 'Widget.loadWidgets.debug.120' =3D> 1, 'TestWidget.crosscheck.info.254' =3D> 1, 'TestWidget.crosscheck.info.267' =3D> 231, 'TestWidget.init.info.42' =3D> 1, 'TestWidget.init.info.67' =3D> 1, 'TestWidget.init.info.68' =3D> 1, 'TestWidget.new_from_xml.debug.128' =3D> 11, 'TestWidget.new_from_xml.debug.143' =3D> 12, 'TestWidget.new_from_xml.debug.165' =3D> 46, 'TestWidget.new_from_xml.debug.197' =3D> 46, 'TestWidget.new_from_xml.error.198' =3D> 3, 'TestWidget.new_from_xml.info.127' =3D> 11, 'TestWidget.new_from_xml.info.173' =3D> 231 } ]; Configuration Given that categories are built on the fly, and that cate=AD gories are reported at application END, you can take the reported categories and roll them back into the log4perl config-file. Other Features Configuration Loading If use Log::Log4perl::AutoCat is given an import list which includes initstr =3D> q{}, or initfile =3D> $filename, the string or file is used to initialize Log::Log4perl. These are simple import-wrappers on existing Log4perl ini=AD tialization techniques. Since this is my 1st project to use Log::Log4perl, I dont have the experience to know why they are not already exposed in Log::Log4perl::import(). Perhaps reasons for not doing so will become apparent as a result of this experimental feature. Aliasing If use Log::Log4perl::AutoCat is given an import list which includes alias =3D> $aliasname, Log::Log4perl::Auto=AD Cat::AUTOLOAD is aliased into package $aliasname. This shorthand is convenient for using class method invocation of the Logger, and is necessary for correct functioning of the features described next. Note: because aliasing is used in optimization phase, it must be imported via use, it cannot be deferred as in require, import. untar and read on.. feedback and patches welcome.. jimc |