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