dotReader
view release on metacpan or search on metacpan
lib/dtRdr/Logger.pm view on Meta::CPAN
move away from that.
=cut
require Exporter;
=head2 import
dtRdr::Logger->import(@args);
=cut
{
# the gymnastics here are really just to allow the test suite to run
# without doing dtRdr->init;
my $did_init = 0;
sub import {
my ($package, $args) = @_;
unless($did_init) {
# if nobody ever inits us, we just dump everything on stderr
my $conf = <<' ---';
log4perl.logger = WARN, Screen
log4perl.appender.Screen = Log::Log4perl::Appender::Screen
log4perl.appender.Screen.stderr = 1
log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.Screen.layout.ConversionPattern=%p - %m at %C line %L%n
---
$conf =~ s/^\s+//mg;
Log::Log4perl->init(\$conf) or die("$!");
$did_init = 1;
}
goto \&Exporter::import;
} # end subroutine import definition
}
########################################################################
our @EXPORT = qw(L RL WARN DBG_DUMP);
=head1 Get Logger
=head2 L
A shortcut to return a logger object FOR YOUR NAMESPACE with an optional
list of subtags.
L($subtag);
Example:
package My::Package;
my $logger = L;
my $logger = L('#foo');
Now $logger will log into the class 'log4perl.logger.My.Package.#foo'.
$subtag MUST start with a #. If this is omitted, it will be changed.
=cut
sub L (@) {
my $class = caller;
my ($tag) = @_;
if(defined($tag) and $tag ne '') {
$tag =~ s/^#*/#/;
$class .= '.' . $tag;
}
Log::Log4perl->get_logger($class);
} # end subroutine L definition
########################################################################
=head2 RL
A shortcut to a root-level logger.
RL($tag);
my $logger = RL('#foo');
Now $logger which will log into the class 'log4perl.logger.#foo'.
$tag MUST start with a #. If this is omitted, it will be changed.
=cut
sub RL {
my ($tag) = @_;
$tag or croak('must have a tag for a root logger');
$tag =~ s/^#*/#/;
Log::Log4perl->get_logger($tag);
} # end subroutine RL definition
########################################################################
sub WARN { local $SIG{__WARN__}; carp(@_); }
=head2 editor
Launches $ENV{THOUT_EDITOR} with a tempfile containing $string.
Just a handy way to get some debugging data into an editor.
dtRdr::Logger->editor($string);
Or, to do lazy evaluation only when needed, pass a sub that returns a
string.
dtRdr::Logger->editor(sub {do_stuff_that_takes_time()});
=cut
sub editor {
my $package = shift;
my ($string) = @_;
unless($ENV{THOUT_EDITOR} and require File::Temp) {
print STDERR "dtRdr::Logger->edit: too bad\n";
return;
}
( run in 1.448 second using v1.01-cache-2.11-cpan-f52f0507bed )