Changed Catalyst::Log to be more compitable with existing modules on CPAN
[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 sub dump { shift->_format( 'dump', Dumper( $_[1] ) ) }
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 =head1 SEE ALSO
82
83 L<Catalyst>.
84
85 =head1 AUTHOR
86
87 Sebastian Riedel, C<sri@cpan.org>
88
89 =head1 COPYRIGHT
90
91 This program is free software, you can redistribute it and/or modify it under
92 the same terms as Perl itself.
93
94 =cut
95
96 1;