From: Arthur Axel 'fREW' Schmidt Date: Sun, 21 Feb 2010 05:54:42 +0000 (-0600) Subject: more complete synopsos and typechecking for logger X-Git-Tag: v0.00100~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5b094c87300079d26d2a4a3b184e1286dba17bc1;p=p5sagit%2FLog-Contextual.git more complete synopsos and typechecking for logger --- diff --git a/lib/Log/Contextual.pm b/lib/Log/Contextual.pm index f2ad999..299f2d7 100644 --- a/lib/Log/Contextual.pm +++ b/lib/Log/Contextual.pm @@ -7,6 +7,7 @@ our $VERSION = '0.00100'; require Exporter; use Data::Dumper::Concise; +use Scalar::Util 'blessed'; BEGIN { our @ISA = qw(Exporter) } @@ -58,15 +59,21 @@ our $Get_Logger; sub set_logger { my $logger = $_[0]; - $logger = do { my $l = $logger; sub { $l } } - if ref $logger ne 'CODE'; + if(ref $logger ne 'CODE') { + die 'logger was not a CodeRef or a logger object. Please try again.' + unless blessed($logger); + $logger = do { my $l = $logger; sub { $l } } + } $Get_Logger = $logger; } sub with_logger { my $logger = $_[0]; - $logger = do { my $l = $logger; sub { $l } } - if ref $logger ne 'CODE'; + if(ref $logger ne 'CODE') { + die 'logger was not a CodeRef or a logger object. Please try again.' + unless blessed($logger); + $logger = do { my $l = $logger; sub { $l } } + } local $Get_Logger = $logger; $_[1]->(); } @@ -310,12 +317,15 @@ Log::Contextual - Simple logging interface with a contextual log =head1 SYNOPSIS - use Log::Log4perl; use Log::Contextual qw( :log :dlog set_logger with_logger ); + use Log::Contextual::SimpleLogger; + use Log::Log4perl ':easy'; + Log::Log4perl->easy_init($DEBUG); - my $logger = sub { Log::Log4perl->get_logger }; - set_logger { $logger }; + my $logger = Log::Log4perl->get_logger; + + set_logger $logger; log_debug { 'program started' }; @@ -330,6 +340,8 @@ Log::Contextual - Simple logging interface with a contextual log }); } + foo(); + =head1 DESCRIPTION This module is a simple interface to extensible logging. It is bundled with a