added optional arguments to Catalyst::Log methods
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Log.pm
CommitLineData
fc7ec1d9 1package Catalyst::Log;
2
3use strict;
4use base 'Class::Accessor::Fast';
9b2bc37b 5use Data::Dumper;
6
7$Data::Dumper::Terse = 1;
fc7ec1d9 8
9=head1 NAME
10
11Catalyst::Log - Catalyst Log Class
12
13=head1 SYNOPSIS
14
82d2fcbe 15 $log = $c->log;
16 $log->debug($msg, @args);
17 $log->dump($ref);
18 $log->error($msg, @args);
19 $log->info($msg, @args);
20 $log->warn($msg, @args);
21
fc7ec1d9 22See L<Catalyst>.
23
24=head1 DESCRIPTION
25
82d2fcbe 26This module provides the default, simple logging functionality for Catalyst.
27If you want something different set C<$c->log> in your application module, e.g.:
28
29 $c->log( MyLogger->new );
30
31Your logging object is expected to provide the interface described here.
32
fc7ec1d9 33
b22c6668 34=head1 METHODS
fc7ec1d9 35
b22c6668 36=over 4
fc7ec1d9 37
82d2fcbe 38=item $log->debug($msg, @args)
b22c6668 39
40Logs a debugging message.
fc7ec1d9 41
42=cut
43
82d2fcbe 44sub debug { _format( 'debug', splice(@_, 1) ) }
fc7ec1d9 45
82d2fcbe 46=item $log->dump($ref)
9b2bc37b 47
b22c6668 48Logs a formatted dump of a variable passed by reference (uses C<Data::Dumper>).
9b2bc37b 49
50=cut
51
52sub dump { _format( 'dump', Dumper( $_[1] ) ) }
53
82d2fcbe 54=item $log->error($msg, @args)
fc7ec1d9 55
b22c6668 56Logs an error message.
fc7ec1d9 57
58=cut
59
82d2fcbe 60sub error { _format( 'error', splice(@_, 1) ) }
fc7ec1d9 61
82d2fcbe 62=item $log->info($msg, @args)
fc7ec1d9 63
b22c6668 64Logs an informational message.
fc7ec1d9 65
66=cut
67
82d2fcbe 68sub info { _format( 'info', splice(@_, 1) ) }
fc7ec1d9 69
82d2fcbe 70=item $log->warn($msg, @args)
fc7ec1d9 71
b22c6668 72Logs a warning message.
fc7ec1d9 73
74=cut
75
82d2fcbe 76sub warn { _format( 'warn', splice(@_, 1) ) }
fc7ec1d9 77
78sub _format {
82d2fcbe 79 if (@_ > 2) {
80 printf STDERR '[' . localtime(time) . "] [catalyst] [$_[0]] $_[1]\n", splice(@_, 2);
81 }
82 else {
83 print STDERR '[' . localtime(time) . "] [catalyst] [$_[0]] $_[1]\n";
84 }
fc7ec1d9 85}
86
b22c6668 87=back
88
fc7ec1d9 89=head1 SEE ALSO
90
91L<Catalyst>.
92
93=head1 AUTHOR
94
95Sebastian Riedel, C<sri@cpan.org>
96
97=head1 COPYRIGHT
98
99This program is free software, you can redistribute it and/or modify it under
100the same terms as Perl itself.
101
102=cut
103
1041;