4 use base 'Class::Accessor::Fast';
9 __PACKAGE__->mk_accessors('level');
10 __PACKAGE__->mk_accessors('body');
11 __PACKAGE__->mk_accessors('abort');
14 my @levels = qw[ debug info warn error fatal ];
16 for ( my $i = 0 ; $i < @levels ; $i++ ) {
18 my $name = $levels[$i];
21 $LEVELS{$name} = $level;
28 if ( $self->{level} & $level ) {
29 $self->_log( $name, @_ );
35 return $self->{level} & $level;
42 my $self = $class->SUPER::new;
43 $self->levels( scalar(@_) ? @_ : keys %LEVELS );
48 my ( $self, @levels ) = @_;
50 $self->enable(@levels);
54 my ( $self, @levels ) = @_;
55 $self->{level} |= $_ for map { $LEVELS{$_} } @levels;
59 my ( $self, @levels ) = @_;
60 $self->{level} &= ~$_ for map { $LEVELS{$_} } @levels;
65 local $Data::Dumper::Terse = 1;
66 $self->info( Dumper( @_ ) );
72 my $time = localtime(time);
73 my $message = join( "\n", @_ );
75 sprintf( "[%s] [catalyst] [%s] %s\n", $time, $level, $message );
80 if ( $self->abort || !$self->body ) {
84 $self->_send_to_log( $self->body );
100 Catalyst::Log - Catalyst Log Class
105 $log->debug($message);
106 $log->info($message);
107 $log->warn($message);
108 $log->error($message);
109 $log->fatal($message);
111 if ( $log->is_debug ) {
112 # expensive debugging
120 This module provides the default, simple logging functionality for Catalyst.
121 If you want something different set C<< $c->log >> in your application module,
124 $c->log( MyLogger->new );
126 Your logging object is expected to provide the interface described here.
133 $log->debug($message);
138 $log->info($message);
143 $log->warn($message);
148 $log->error($message);
153 $log->fatal($message);
159 Constructor. Defaults to enable all levels unless levels are provided in
162 $log = Catalyst::Log->new;
163 $log = Catalyst::Log->new( 'warn', 'error' );
169 $log->levels( 'warn', 'error', 'fatal' );
175 $log->enable( 'warn', 'error' );
181 $log->disable( 'warn', 'error' );
193 Is the log level active?
197 Should Catalyst emit logs for this request? Will be reset at the end of
200 *NOTE* This method is not compatible with other log apis, so if you plan
201 to use Log4Perl or another logger, you should call it like this:
203 $c->log->abort(1) if $c->log->can('abort');
207 $log->_send_to_log( @messages );
209 This protected method is what actually sends the log information to STDERR.
210 You may subclass this module and override this method to get finer control
219 Sebastian Riedel, C<sri@cpan.org>
220 Marcus Ramberg, C<mramberg@cpan.org>
221 Christian Hansen, C<ch@ngmedia.com>
225 This program is free software, you can redistribute it and/or modify
226 it under the same terms as Perl itself.