I want to accept a log in several utility classes, for example. d. DBI. What is the best thing to do with Log :: Log4perl?
I think this is normal for a DBI subclass (let's say MyDBI) and override some methods there to make them log. But there is a problem with the categories. If you create a registrar with
Log::Log4perl->get_logger(ref $self || $self)
then all journal entries belong MyDBI, and it would be difficult to filter them out. Therefore, I’d better pass the registrar to MyDBIfrom the calling module (say, MyModule) so that the category is semantically correct. The first question is, is it good at all? I mean, are there any hidden reefs regarding this approach?
The second question is how to transfer the registrar to MyDBI? I have an idea to declare a global variable, e. d. $MyDBI::loggerand set in the calling method:
local $MyDBI::logger = Log::Log4perl->get_logger(ref $self || $self);
There is a traditional dislike of global variables. Can you come up with a better way?
EDIT: Of course, the best code is not code. callerit would be enough if it takes into account inheritance.
Third question: is it possible to enter both categories, MyDBIand MyModule, with Log :: Log4perl, if they are not hierarchically related?
source
share