revised documentation for 5.0
[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 
26 Catalyst.
27 If you want something different set C<$c->log> in your application 
28 module, e.g.:
29
30     $c->log( MyLogger->new );
31
32 Your logging object is expected to provide the interface described here.
33
34
35 =head1 METHODS
36
37 =over 4
38
39 =item $log->debug(@message)
40
41 Logs a debugging message.
42
43 =cut
44
45 sub debug { shift->_format( 'debug', @_ ) }
46
47 =item $log->error(@message)
48
49 Logs an error message.
50
51 =cut
52
53 sub error { shift->_format( 'error', @_ ) }
54
55 =item $log->info(@message)
56
57 Logs an informational message.
58
59 =cut
60
61 sub info { shift->_format( 'info', @_ ) }
62
63 =item $log->warn(@message)
64
65 Logs a warning message.
66
67 =cut
68
69 sub warn { shift->_format( 'warn', @_ ) }
70
71 sub _format {
72     my $class   = shift;
73     my $level   = shift;
74     my $time    = localtime(time);
75     my $message = join( "\n", @_ );
76     printf( STDERR "[%s] [catalyst] [%s] %s\n", $time, $level, $message );
77 }
78
79 =back
80
81 =cut
82
83 # Private - Logs a Data::Dumper of reference.
84 sub _dump { shift->_format( 'dump', Dumper( $_[0] ) ) }
85
86
87 =head1 SEE ALSO
88
89 L<Catalyst>.
90
91 =head1 AUTHOR
92
93 Sebastian Riedel, C<sri@cpan.org>
94 Marcus Ramberg, C<mramberg@cpan.org>
95
96 =head1 COPYRIGHT
97
98 This program is free software, you can redistribute it and/or modify 
99 it under the same terms as Perl itself.
100
101 =cut
102
103 1;