Closed targzeta closed 3 years ago
There's an FAQ entry "My new module uses Log4perl -- but what happens if the calling program didn't configure it?". The answer is:
If a Perl module uses Log::Log4perl, it will typically rely on the calling program to initialize it. If it is using Log::Log4perl in
:easy
mode, like inpackage MyMod; use Log::Log4perl qw(:easy); sub foo { DEBUG("In foo"); } 1;
and the calling program doesn't initialize Log::Log4perl at all (e.g. because it has no clue that it's available), Log::Log4perl will silently ignore all logging messages.
Hi, I have written a module that actually uses Log4Perl as logging system. This is how I use Log4Perl:
Now, I don't know if the logger it was initialized or not by the main program. If not, the main program receives:
Is there a transparent way to use Log4perl only if the main has configured it? So that the get_logger() returns always an instance that doesn't do nothing.
Actually I have in the main program:
but I think that a module should be independent from who use it.
Thank you in advance, Emanuele