Item10328: use the writeDebug, luke!

pencil
Priority: Enhancement
Current State: New
Released In: n/a
Target Release: n/a
Applies To: Extension
Component: MongoDBPlugin
Branches: trunk
Reported By: PaulHarvey
Waiting For: Main.SvenDowideit
Last Change By: PaulHarvey
Here's some code in datumhandler. it squelches to the loglevel set via LocalSite.cfg, and every call to it specifies the method name and log level it is (more higher means more noisy).

Which is really lame (depending on the caller to supply its method name? ew!) but might inspire you to do something better

sub writeDebug {
    my ( $message, $method, $level, $package, $refdebuglevel ) = @_;
    my @lines;

    if ( not defined $refdebuglevel ) {
        $refdebuglevel =
          (      $debuglevel
              || $Foswiki::cfg{Plugins}{DatumTypeExternalDataPlugin}{Debug}
              || 0 );
    }
    if ( $refdebuglevel and ( not defined $level or $level <= $refdebuglevel ) )
    {
        @lines = split( /[\r\n]+/, $message );
        foreach my $line (@lines) {
            my @packparts = split( /::/, ( $package || __PACKAGE__ ) );
            my $logline = '::'
              . $packparts[ scalar(@packparts) - 1 ]
              . "::$method():\t$line\n";

            if ( defined &Foswiki::Func::writeDebug ) {
                Foswiki::Func::writeDebug($logline);
            }
            else {    # CLI
                print STDERR $logline;
            }
        }
    }

    return;
}

-- PaulHarvey - 08 Feb 2011

E.g.
writeDebug("I am a fish", 'fishMethod', 3);

-- PaulHarvey - 08 Feb 2011
 
Topic revision: r6 - 08 Dec 2011, PaulHarvey - This page was cached on 20 Oct 2020 - 10:59.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy