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.
124 Good alternatives to consider are Log::Log4Perl and Log::Dispatch.
126 If you want to be able to log arbitrary warnings, you can do something along
129 $SIG{__WARN__} = sub { MyApp->log->warn(@_); };
131 however this is (a) global, (b) hairy and (c) may have unexpected side effects.
132 Don't say we didn't warn you.
139 $log->debug($message);
144 $log->info($message);
149 $log->warn($message);
154 $log->error($message);
159 $log->fatal($message);
165 Constructor. Defaults to enable all levels unless levels are provided in
168 $log = Catalyst::Log->new;
169 $log = Catalyst::Log->new( 'warn', 'error' );
175 $log->levels( 'warn', 'error', 'fatal' );
181 $log->enable( 'warn', 'error' );
187 $log->disable( 'warn', 'error' );
199 Is the log level active?
203 Should Catalyst emit logs for this request? Will be reset at the end of
206 *NOTE* This method is not compatible with other log apis, so if you plan
207 to use Log4Perl or another logger, you should call it like this:
209 $c->log->abort(1) if $c->log->can('abort');
213 $log->_send_to_log( @messages );
215 This protected method is what actually sends the log information to STDERR.
216 You may subclass this module and override this method to get finer control
225 Sebastian Riedel, C<sri@cpan.org>
226 Marcus Ramberg, C<mramberg@cpan.org>
227 Christian Hansen, C<ch@ngmedia.com>
231 This program is free software, you can redistribute it and/or modify
232 it under the same terms as Perl itself.