Just another Perl shrine | |
PerlMonks |
Log::Log4perl use strategiesby Excalibor (Pilgrim) |
on May 09, 2006 at 10:18 UTC ( [id://548168]=perlquestion: print w/replies, xml ) | Need Help?? |
Excalibor has asked for the wisdom of the Perl Monks concerning the following question: Dear monastery brothers, I am using Log::Log4perl on a fairly complex project, and I have been assailed by doubt as of late. I got this error at the end of a Test::Harness run: (in cleanup) Internal error: Root Logger not initialized. at /usr/share/perl5/Log/Log4perl/Logger.pm line 521 during global destruction. Now, I started to look why I get this error, and I cannot find why. But I thought it could be due to some module being called (or not being called) because the way I was handling the logging objects. So I started to think, again, on the loggers and how I am using them. I have wrapped the Log::Log4perl->init() call within a module, which gets use()d right at the start of every package, so the root logger, and everything else, like configuration file, appenders, etc is handled rightly. Then, I am using my class hierarchy as the logger categories, as suggested. However, there are several ways to get to the loggers, and maybe I'm not using the best one. Some examples follow. This is the way I am using it (strategy A):
Now, I have this possibility (strategy B):
Using this testing code
yields the expected result (please, don't mind the format, I am reusing the project format, and this is not the default output):
Now, being a singleton, there shouldn't be any differences beetween the lexical-to-the-package logger and the lexical-to-the-object one, right? So which one is better, A or B? 'A' allows writing less and don't fiddling with your objects guts (which is what B does, but it's also hiding things, "encapsulating"), but it gives the same object to all instances. A 'C' approach would be to get the logger in every method that needs it, but I don't see that different (in this singleton-based logging method) to method A. I can devise even other logging strategies as well, but they are even more contorted (I haven't checked the Aspect Oriented Programming mentioned in other Log::Log4perl threads in the monastery library). So, in this case of Log::Log4perl, which strategy is best to use? A package lexical logger (A), an instance-contained lexical logger (B), or a procedure lexical logger (C)? And, in general (forgetting it's a singleton), would you prefer A, B, or C (or any other) for your OO projects? Thank you very much for your help. --
Back to
Seekers of Perl Wisdom
|
|