Commit | Line | Data |
fc7ec1d9 |
1 | package Catalyst::Log; |
2 | |
3 | use strict; |
4 | use base 'Class::Accessor::Fast'; |
9b2bc37b |
5 | use Data::Dumper; |
6 | |
7 | $Data::Dumper::Terse = 1; |
fc7ec1d9 |
8 | |
9 | =head1 NAME |
10 | |
11 | Catalyst::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 |
22 | See L<Catalyst>. |
23 | |
24 | =head1 DESCRIPTION |
25 | |
82d2fcbe |
26 | This module provides the default, simple logging functionality for Catalyst. |
27 | If you want something different set C<$c->log> in your application module, e.g.: |
28 | |
29 | $c->log( MyLogger->new ); |
30 | |
31 | Your 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 | |
40 | Logs a debugging message. |
fc7ec1d9 |
41 | |
42 | =cut |
43 | |
82d2fcbe |
44 | sub debug { _format( 'debug', splice(@_, 1) ) } |
fc7ec1d9 |
45 | |
82d2fcbe |
46 | =item $log->dump($ref) |
9b2bc37b |
47 | |
b22c6668 |
48 | Logs a formatted dump of a variable passed by reference (uses C<Data::Dumper>). |
9b2bc37b |
49 | |
50 | =cut |
51 | |
52 | sub dump { _format( 'dump', Dumper( $_[1] ) ) } |
53 | |
82d2fcbe |
54 | =item $log->error($msg, @args) |
fc7ec1d9 |
55 | |
b22c6668 |
56 | Logs an error message. |
fc7ec1d9 |
57 | |
58 | =cut |
59 | |
82d2fcbe |
60 | sub error { _format( 'error', splice(@_, 1) ) } |
fc7ec1d9 |
61 | |
82d2fcbe |
62 | =item $log->info($msg, @args) |
fc7ec1d9 |
63 | |
b22c6668 |
64 | Logs an informational message. |
fc7ec1d9 |
65 | |
66 | =cut |
67 | |
82d2fcbe |
68 | sub info { _format( 'info', splice(@_, 1) ) } |
fc7ec1d9 |
69 | |
82d2fcbe |
70 | =item $log->warn($msg, @args) |
fc7ec1d9 |
71 | |
b22c6668 |
72 | Logs a warning message. |
fc7ec1d9 |
73 | |
74 | =cut |
75 | |
82d2fcbe |
76 | sub warn { _format( 'warn', splice(@_, 1) ) } |
fc7ec1d9 |
77 | |
78 | sub _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 | |
91 | L<Catalyst>. |
92 | |
93 | =head1 AUTHOR |
94 | |
95 | Sebastian Riedel, C<sri@cpan.org> |
96 | |
97 | =head1 COPYRIGHT |
98 | |
99 | This program is free software, you can redistribute it and/or modify it under |
100 | the same terms as Perl itself. |
101 | |
102 | =cut |
103 | |
104 | 1; |