From: Arthur Axel 'fREW' Schmidt Date: Sun, 14 Feb 2010 19:16:09 +0000 (-0600) Subject: add different kinds of logging X-Git-Tag: v0.00100~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6dc6632a7dae8a54b60f167c7875515b08f1c010;p=p5sagit%2FLog-Contextual.git add different kinds of logging --- diff --git a/lib/Log/Contextual.pm b/lib/Log/Contextual.pm index 6ce2431..4f757cd 100644 --- a/lib/Log/Contextual.pm +++ b/lib/Log/Contextual.pm @@ -16,12 +16,42 @@ sub set_logger { $Get_Logger = $_[0]; } +sub log_trace (&) { + my $log = $Get_Logger->(); + $log->trace($_[0]->()) + if $log->is_trace; +} + sub log_debug (&) { my $log = $Get_Logger->(); $log->debug($_[0]->()) if $log->is_debug; } +sub log_info (&) { + my $log = $Get_Logger->(); + $log->info($_[0]->()) + if $log->is_info; +} + +sub log_warn (&) { + my $log = $Get_Logger->(); + $log->warn($_[0]->()) + if $log->is_warn; +} + +sub log_error (&) { + my $log = $Get_Logger->(); + $log->error($_[0]->()) + if $log->is_error; +} + +sub log_fatal (&) { + my $log = $Get_Logger->(); + $log->fatal($_[0]->()) + if $log->is_fatal; +} + sub with_logger (&$) { local $Get_Logger = $_[1]; $_[0]->(); diff --git a/lib/Log/Contextual/Sugar.pm b/lib/Log/Contextual/Sugar.pm index eecc46d..781552b 100644 --- a/lib/Log/Contextual/Sugar.pm +++ b/lib/Log/Contextual/Sugar.pm @@ -9,6 +9,24 @@ BEGIN { @ISA = qw(Exporter) } use Data::Dumper::Concise; use Log::Contextual (); +sub Dlog_trace (&@) { + my $code = shift; + my @values = @_; + Log::Contextual::log_trace { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + }; + @values +} + +sub DlogS_trace (&$) { + my $code = $_[0]; + my $value = $_[1]; + Log::Contextual::log_trace { + do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; + }; + $value +} + sub Dlog_debug (&@) { my $code = shift; my @values = @_; @@ -27,4 +45,76 @@ sub DlogS_debug (&$) { $value } +sub Dlog_info (&@) { + my $code = shift; + my @values = @_; + Log::Contextual::log_info { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + }; + @values +} + +sub DlogS_info (&$) { + my $code = $_[0]; + my $value = $_[1]; + Log::Contextual::log_info { + do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; + }; + $value +} + +sub Dlog_warn (&@) { + my $code = shift; + my @values = @_; + Log::Contextual::log_warn { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + }; + @values +} + +sub DlogS_warn (&$) { + my $code = $_[0]; + my $value = $_[1]; + Log::Contextual::log_warn { + do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; + }; + $value +} + +sub Dlog_error (&@) { + my $code = shift; + my @values = @_; + Log::Contextual::log_error { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + }; + @values +} + +sub DlogS_error (&$) { + my $code = $_[0]; + my $value = $_[1]; + Log::Contextual::log_error { + do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; + }; + $value +} + +sub Dlog_fatal (&@) { + my $code = shift; + my @values = @_; + Log::Contextual::log_fatal { + do { local $_ = Data::Dumper::Concise::Dumper @values; $code->() }; + }; + @values +} + +sub DlogS_fatal (&$) { + my $code = $_[0]; + my $value = $_[1]; + Log::Contextual::log_fatal { + do { local $_ = Data::Dumper::Concise::Dumper $value; $code->() }; + }; + $value +} + 1;