X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FLog.pm;h=822ea32b0312676c207ae0bd9e1f2c1dbe45c538;hp=01ff75f603a46e27b63443e34a01fa64067e3876;hb=e8b9f2a92084b3b9dab6b2b879900481b8548b3b;hpb=6323fda2e7ace0fc0aa06305c674957cedc6d025 diff --git a/lib/Catalyst/Log.pm b/lib/Catalyst/Log.pm index 01ff75f..822ea32 100644 --- a/lib/Catalyst/Log.pm +++ b/lib/Catalyst/Log.pm @@ -1,20 +1,14 @@ package Catalyst::Log; use strict; -#use base 'Class::Accessor::Fast'; +use base 'Class::Accessor::Fast'; use Data::Dump; our %LEVELS = (); -use Moose; - -has level => (is => 'rw'); -has _body => (is => 'rw'); -has abort => (is => 'rw'); - -#__PACKAGE__->mk_accessors('level'); -#__PACKAGE__->mk_accessors('body'); -#__PACKAGE__->mk_accessors('abort'); +__PACKAGE__->mk_accessors('level'); +__PACKAGE__->mk_accessors('body'); +__PACKAGE__->mk_accessors('abort'); { my @levels = qw[ debug info warn error fatal ]; @@ -31,14 +25,14 @@ has abort => (is => 'rw'); *{$name} = sub { my $self = shift; - if ( $self->level & $level ) { + if ( $self->{level} & $level ) { $self->_log( $name, @_ ); } }; *{"is_$name"} = sub { my $self = shift; - return $self->level & $level; + return $self->{level} & $level; }; } } @@ -58,20 +52,12 @@ sub levels { sub enable { my ( $self, @levels ) = @_; - my $level = $self->level; - for(map { $LEVELS{$_} } @levels){ - $level |= $_; - } - $self->level($level); + $self->{level} |= $_ for map { $LEVELS{$_} } @levels; } sub disable { my ( $self, @levels ) = @_; - my $level = $self->level; - for(map { $LEVELS{$_} } @levels){ - $level &= ~$_; - } - $self->level($level); + $self->{level} &= ~$_ for map { $LEVELS{$_} } @levels; } sub _dump { @@ -84,20 +70,18 @@ sub _log { my $level = shift; my $message = join( "\n", @_ ); $message .= "\n" unless $message =~ /\n$/; - my $body = $self->_body; - $body .= sprintf( "[%s] %s", $level, $message ); - $self->_body($body); + $self->{body} .= sprintf( "[%s] %s", $level, $message ); } sub _flush { my $self = shift; - if ( $self->abort || !$self->_body ) { + if ( $self->abort || !$self->body ) { $self->abort(undef); } else { - $self->_send_to_log( $self->_body ); + $self->_send_to_log( $self->body ); } - $self->_body(undef); + $self->body(undef); } sub _send_to_log { @@ -185,10 +169,6 @@ arguments. $log = Catalyst::Log->new; $log = Catalyst::Log->new( 'warn', 'error' ); -=head2 level - -Contains a bitmask of the currently set log levels. - =head2 levels Set log levels @@ -237,8 +217,6 @@ This protected method is what actually sends the log information to STDERR. You may subclass this module and override this method to get finer control over the log output. -=head2 meta - =head1 SEE ALSO L.