8 has level => (is => 'rw');
9 has _body => (is => 'rw');
10 has abort => (is => 'rw');
13 my @levels = qw[ debug info warn error fatal ];
15 for ( my $i = 0 ; $i < @levels ; $i++ ) {
17 my $name = $levels[$i];
20 $LEVELS{$name} = $level;
27 if ( $self->level & $level ) {
28 $self->_log( $name, @_ );
34 return $self->level & $level;
42 my $self = $class->$orig;
43 $self->levels( scalar(@_) ? @_ : keys %LEVELS );
48 my ( $self, @levels ) = @_;
50 $self->enable(@levels);
54 my ( $self, @levels ) = @_;
55 my $level = $self->level;
56 for(map { $LEVELS{$_} } @levels){
63 my ( $self, @levels ) = @_;
64 my $level = $self->level;
65 for(map { $LEVELS{$_} } @levels){
73 $self->info( Data::Dump::dump(@_) );
79 my $message = join( "\n", @_ );
80 $message .= "\n" unless $message =~ /\n$/;
81 my $body = $self->_body;
82 $body .= sprintf( "[%s] %s", $level, $message );
88 if ( $self->abort || !$self->_body ) {
92 $self->_send_to_log( $self->_body );
108 Catalyst::Log - Catalyst Log Class
113 $log->debug($message);
114 $log->info($message);
115 $log->warn($message);
116 $log->error($message);
117 $log->fatal($message);
119 if ( $log->is_debug ) {
120 # expensive debugging
128 This module provides the default, simple logging functionality for Catalyst.
129 If you want something different set C<< $c->log >> in your application module,
132 $c->log( MyLogger->new );
134 Your logging object is expected to provide the interface described here.
135 Good alternatives to consider are Log::Log4Perl and Log::Dispatch.
137 If you want to be able to log arbitrary warnings, you can do something along
140 $SIG{__WARN__} = sub { MyApp->log->warn(@_); };
142 however this is (a) global, (b) hairy and (c) may have unexpected side effects.
143 Don't say we didn't warn you.
150 $log->debug($message);
155 $log->info($message);
160 $log->warn($message);
165 $log->error($message);
170 $log->fatal($message);
176 Constructor. Defaults to enable all levels unless levels are provided in
179 $log = Catalyst::Log->new;
180 $log = Catalyst::Log->new( 'warn', 'error' );
184 Contains a bitmask of the currently set log levels.
190 $log->levels( 'warn', 'error', 'fatal' );
196 $log->enable( 'warn', 'error' );
202 $log->disable( 'warn', 'error' );
214 Is the log level active?
218 Should Catalyst emit logs for this request? Will be reset at the end of
221 *NOTE* This method is not compatible with other log apis, so if you plan
222 to use Log4Perl or another logger, you should call it like this:
224 $c->log->abort(1) if $c->log->can('abort');
228 $log->_send_to_log( @messages );
230 This protected method is what actually sends the log information to STDERR.
231 You may subclass this module and override this method to get finer control
242 Sebastian Riedel, C<sri@cpan.org>
243 Marcus Ramberg, C<mramberg@cpan.org>
244 Christian Hansen, C<ch@ngmedia.com>
248 This program is free software, you can redistribute it and/or modify
249 it under the same terms as Perl itself.
253 __PACKAGE__->meta->make_immutable;