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 $self->info( Data::Dump::dump(@_) );
71 my $message = join( "\n", @_ );
72 $self->{body} .= sprintf( "[%s] %s\n", $level, $message );
77 if ( $self->abort || !$self->body ) {
81 $self->_send_to_log( $self->body );
97 Catalyst::Log - Catalyst Log Class
102 $log->debug($message);
103 $log->info($message);
104 $log->warn($message);
105 $log->error($message);
106 $log->fatal($message);
108 if ( $log->is_debug ) {
109 # expensive debugging
117 This module provides the default, simple logging functionality for Catalyst.
118 If you want something different set C<< $c->log >> in your application module,
121 $c->log( MyLogger->new );
123 Your logging object is expected to provide the interface described here.
130 $log->debug($message);
135 $log->info($message);
140 $log->warn($message);
145 $log->error($message);
150 $log->fatal($message);
156 Constructor. Defaults to enable all levels unless levels are provided in
159 $log = Catalyst::Log->new;
160 $log = Catalyst::Log->new( 'warn', 'error' );
166 $log->levels( 'warn', 'error', 'fatal' );
172 $log->enable( 'warn', 'error' );
178 $log->disable( 'warn', 'error' );
190 Is the log level active?
194 Should Catalyst emit logs for this request? Will be reset at the end of
197 *NOTE* This method is not compatible with other log apis, so if you plan
198 to use Log4Perl or another logger, you should call it like this:
200 $c->log->abort(1) if $c->log->can('abort');
204 $log->_send_to_log( @messages );
206 This protected method is what actually sends the log information to STDERR.
207 You may subclass this module and override this method to get finer control
216 Sebastian Riedel, C<sri@cpan.org>
217 Marcus Ramberg, C<mramberg@cpan.org>
218 Christian Hansen, C<ch@ngmedia.com>
222 This program is free software, you can redistribute it and/or modify
223 it under the same terms as Perl itself.