Item10328: use the writeDebug, luke!
Priority: Enhancement
Current State: New
Released In: n/a
Target Release: n/a
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