removed cgi-server.pl
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Log.pm
index 7ae9f07..087789f 100644 (file)
@@ -2,6 +2,9 @@ package Catalyst::Log;
 
 use strict;
 use base 'Class::Accessor::Fast';
+use Data::Dumper;
+
+$Data::Dumper::Terse = 1;
 
 =head1 NAME
 
@@ -9,50 +12,80 @@ Catalyst::Log - Catalyst Log Class
 
 =head1 SYNOPSIS
 
+    $log = $c->log;
+    $log->debug($msg, @args);
+    $log->dump($ref);
+    $log->error($msg, @args);
+    $log->info($msg, @args);
+    $log->warn($msg, @args);
+
 See L<Catalyst>.
 
 =head1 DESCRIPTION
 
-Simple logging functionality for Catalyst.
+This module provides the default, simple logging functionality for Catalyst.
+If you want something different set C<$c->log> in your application module, e.g.:
+
+    $c->log( MyLogger->new );
+
+Your logging object is expected to provide the interface described here.
+
+
+=head1 METHODS
 
-=head2 METHODS
+=over 4
 
-=head3 debug
+=item $log->debug($msg, @args)
 
-Log debug informations.
+Logs a debugging message.
 
 =cut
 
-sub debug { _format( 'debug', $_[1] ) }
+sub debug { _format( 'debug', splice(@_, 1) ) }
 
-=head3 error
+=item $log->dump($ref)
 
-Log error informations.
+Logs a formatted dump of a variable passed by reference (uses C<Data::Dumper>).
 
 =cut
 
-sub error { _format( 'error', $_[1] ) }
+sub dump { _format( 'dump', Dumper( $_[1] ) ) }
 
-=head3 info
+=item $log->error($msg, @args)
 
-Log informations.
+Logs an error message.
 
 =cut
 
-sub info { _format( 'info', $_[1] ) }
+sub error { _format( 'error', splice(@_, 1) ) }
 
-=head3 warn
+=item $log->info($msg, @args)
 
-Log warnings.
+Logs an informational message.
 
 =cut
 
-sub warn { _format( 'warn', $_[1] ) }
+sub info { _format( 'info', splice(@_, 1) ) }
+
+=item $log->warn($msg, @args)
+
+Logs a warning message.
+
+=cut
+
+sub warn { _format( 'warn', splice(@_, 1) ) }
 
 sub _format {
-    print STDERR '[' . localtime(time) . "] [catalyst] [$_[0]] $_[1]\n";
+    if (@_ > 2) {
+       printf STDERR '[' . localtime(time) . "] [catalyst] [$_[0]] $_[1]\n", splice(@_, 2);
+    }
+    else {
+       print STDERR '[' . localtime(time) . "] [catalyst] [$_[0]] $_[1]\n";
+    }
 }
 
+=back
+
 =head1 SEE ALSO
 
 L<Catalyst>.