in reply to Global or not global

Log::Log4perl solves this elegantly by providing a singleton. So you can add logging whereever you want simply by calling get_logger).

How is calling my $log = Log::Log4perl->get_logger("My::MegaPackage") in every function or method: elegant?

Surely they could have fitted another couple of "log"s in there somewhere.

Maybe my $log_logger = Log::Log4perl->get_log_logger( ... )


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: Global or not global
by McA (Priest) on Jul 03, 2012 at 06:54 UTC
    Hi,
    I use it it this way
    use Log::Log4perl qw(get_logger :nowarn); ... get_logger->info("Shit happens");
    IMHO when you have decided to use Log::Log4perl then it is in the installation prerequisites. To have a function name like 'get_logger' is unique enough for loading it in your current namespace. When Log::Log4perl is not initialized, the code doesn't hurt. So, whenever I need an additional log statement, I just insert get_logger->error("Somewhat");

    That what I meant with 'elegant'. Or call is 'handy'.

    What is your solution to those cross cutting concerns like logging?

    Best regards
    McA
      What is your solution to those cross cutting concerns like logging?

      What is logging? Simply stated, it is printing to a filehandle.

      Pretty much everyone is comfortable using STDOUT and STDERR. And STDERR serves all my logging needs.

      But if you want your logging to go to a different place than STDERR, what's wrong with (say) STDLOG?

      Point it to a file or port as needed.

      Want to turn logging off, direct it to the null device.

      Want your logging to add boilerplate (timestamps, callstack, threadids etc.), tie *STDLOG.

      Once it is tied, routing to multiple destinations is easy.

      IMO, L::L4p is a "let's pretend we're java bunnies", grandiose overkill, behemoth of a package dynasty of packages, that makes writing a few bits of text to a file, laborious, complicated and expensive.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        Hi,
        thank you for sharing your opinion.

        Can you tell me how you insert logging aka. print statements to STDLOG in modules you build? Do you have some kind of resilence if STDLOG is not set up from the using script?

        Best regards
        McA