nysus has asked for the wisdom of the Perl Monks concerning the following question:

I'm now readying my first major (more than a couple dozen lines of code) module to CPAN. I used Log4Perl and a Log4Perl wrapper with some convenience methods I wrote to make it easy to debug and trace the execution of my code while writing it.

What's the best practice as far as leaving this code in the official CPAN release? On the one hand, I don't want to clutter up the code and require users to install Log4Perl and my wrapper for log commands that will be turned off by default for them anyway. On the other hand, I'd rather avoid having to adding/removing the necessary use and various log commands when it comes time to add a new feature or debug existing code.

I've never seen a CPAN module that was littered with debug statements so I'm thinking I should just pull out the Log4perl module and all related statements.

But maybe there is some way I can get the best of both worlds? Maybe just leave the logging code in there an comment them out?

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: Leave log4perl debug code in cpan module?
by Dallaylaen (Chaplain) on Jan 29, 2018 at 09:33 UTC

    Hello nysus,

    Have you considered Log::Any? It can log to STDERR or just skip logging by default, yet if the user of your module wants Log4perl, Log::Any will work with it just fine.

    I'd say it's a bad idea to impose Log::Log4perl upon your future users. It is a very good logger, but not the only one out there.

      No, but I'll read up on it. Looks interesting. Thanks.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

Re: Leave log4perl debug code in cpan module?
by Corion (Patriarch) on Jan 29, 2018 at 08:44 UTC

    Why not make Log::Log4perl a Prerequisite for your module? That way, your users can decide whether or not they want to see the log messages...

    I've decided on needing Log::Log4perl with WWW::Mechanize::Chrome instead of writing another logging implementation myself, to give others the chance of reusing and integrating it.

    The downside I've found is that now every script and test script also has to initialize Log::Log4perl or a warning will be issued. But that's just two lines of configuration:

    use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($ERROR);

    And whenever I need more information, I have to change $ERROR to $TRACE (or maybe $DEBUG).

      Ok, if it's a practice you follow, it's good enough for me. Thanks.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks