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 my $meta = __PACKAGE__->meta;
16 for ( my $i = 0 ; $i < @levels ; $i++ ) {
18 my $name = $levels[$i];
21 $LEVELS{$name} = $level;
23 $meta->add_method($name, sub {
26 if ( $self->level & $level ) {
27 $self->_log( $name, @_ );
31 $meta->add_method("is_$name", sub {
33 return $self->level & $level;
41 my $self = $class->$orig;
42 $self->levels( scalar(@_) ? @_ : keys %LEVELS );
47 my ( $self, @levels ) = @_;
49 $self->enable(@levels);
53 my ( $self, @levels ) = @_;
54 my $level = $self->level;
55 for(map { $LEVELS{$_} } @levels){
62 my ( $self, @levels ) = @_;
63 my $level = $self->level;
64 for(map { $LEVELS{$_} } @levels){
72 $self->info( Data::Dump::dump(@_) );
78 my $message = join( "\n", @_ );
79 $message .= "\n" unless $message =~ /\n$/;
80 my $body = $self->_body;
81 $body .= sprintf( "[%s] %s", $level, $message );
87 if ( $self->abort || !$self->_body ) {
91 $self->_send_to_log( $self->_body );
102 __PACKAGE__->meta->make_immutable();
110 Catalyst::Log - Catalyst Log Class
115 $log->debug($message);
116 $log->info($message);
117 $log->warn($message);
118 $log->error($message);
119 $log->fatal($message);
121 if ( $log->is_debug ) {
122 # expensive debugging
130 This module provides the default, simple logging functionality for Catalyst.
131 If you want something different set C<< $c->log >> in your application module,
134 $c->log( MyLogger->new );
136 Your logging object is expected to provide the interface described here.
137 Good alternatives to consider are Log::Log4Perl and Log::Dispatch.
139 If you want to be able to log arbitrary warnings, you can do something along
142 $SIG{__WARN__} = sub { MyApp->log->warn(@_); };
144 however this is (a) global, (b) hairy and (c) may have unexpected side effects.
145 Don't say we didn't warn you.
152 $log->debug($message);
157 $log->info($message);
162 $log->warn($message);
167 $log->error($message);
172 $log->fatal($message);
178 Constructor. Defaults to enable all levels unless levels are provided in
181 $log = Catalyst::Log->new;
182 $log = Catalyst::Log->new( 'warn', 'error' );
186 Contains a bitmask of the currently set log levels.
192 $log->levels( 'warn', 'error', 'fatal' );
198 $log->enable( 'warn', 'error' );
204 $log->disable( 'warn', 'error' );
216 Is the log level active?
220 Should Catalyst emit logs for this request? Will be reset at the end of
223 *NOTE* This method is not compatible with other log apis, so if you plan
224 to use Log4Perl or another logger, you should call it like this:
226 $c->log->abort(1) if $c->log->can('abort');
230 $log->_send_to_log( @messages );
232 This protected method is what actually sends the log information to STDERR.
233 You may subclass this module and override this method to get finer control
244 Sebastian Riedel, C<sri@cpan.org>
245 Marcus Ramberg, C<mramberg@cpan.org>
246 Christian Hansen, C<ch@ngmedia.com>
250 This program is free software, you can redistribute it and/or modify
251 it under the same terms as Perl itself.
255 __PACKAGE__->meta->make_immutable;