X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FLog.pm;h=2418302cddbb186b32069dcfd352dd74468522df;hb=31213ebcb811c9c11e004ebefac1f6f9aca2ea3d;hp=42aff02f82fe4c9aa056dac6e0b98069f085dfa4;hpb=d298046a19660552a63dc7017bc0d37c62dcb38e;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Log.pm b/lib/Catalyst/Log.pm old mode 100644 new mode 100755 index 42aff02..2418302 --- a/lib/Catalyst/Log.pm +++ b/lib/Catalyst/Log.pm @@ -4,7 +4,7 @@ use Moose; with 'MooseX::Emulate::Class::Accessor::Fast'; use Data::Dump; -use Class::MOP (); +use Moose::Util 'find_meta'; use Carp qw/ cluck /; our %LEVELS = (); # Levels stored as bit field, ergo debug = 1, warn = 2 etc @@ -13,6 +13,7 @@ our %LEVEL_MATCH = (); # Stored as additive, thus debug = 31, warn = 30 etc has level => (is => 'rw'); has _body => (is => 'rw'); has abort => (is => 'rw'); +has autoflush => (is => 'rw'); has _psgi_logger => (is => 'rw', predicate => '_has_psgi_logger', clearer => '_clear_psgi_logger'); has _psgi_errors => (is => 'rw', predicate => '_has_psgi_errors', clearer => '_clear_psgi_errors'); @@ -33,7 +34,7 @@ sub psgienv { { my @levels = qw[ debug info warn error fatal ]; - my $meta = Class::MOP::get_metaclass_by_name(__PACKAGE__); + my $meta = find_meta(__PACKAGE__); my $summed_level = 0; for ( my $i = $#levels ; $i >= 0 ; $i-- ) { @@ -107,8 +108,9 @@ sub _log { my $self = shift; my $level = shift; my $message = join( "\n", @_ ); + my $ret; if ($self->can('_has_psgi_logger') and $self->_has_psgi_logger) { - $self->_psgi_logger->({ + $ret = $self->_psgi_logger->({ level => $level, message => $message, }); @@ -116,8 +118,12 @@ sub _log { $message .= "\n" unless $message =~ /\n$/; my $body = $self->_body; $body .= sprintf( "[%s] %s", $level, $message ); - $self->_body($body); + $ret = $self->_body($body); } + if( $self->autoflush && !$self->abort ) { + $self->_flush; + } + return $ret; } sub _flush { @@ -162,6 +168,8 @@ __PACKAGE__->meta->make_immutable(inline_constructor => 0); __END__ +=for stopwords psgienv + =head1 NAME Catalyst::Log - Catalyst Log Class @@ -282,6 +290,14 @@ to use Log4Perl or another logger, you should call it like this: $c->log->abort(1) if $c->log->can('abort'); +=head2 autoflush + +When enabled, messages are written to the log immediately instead of queued +until the end of the request. By default, autoflush is enabled during setup, +but turned back off thereafter. This is done purely for legacy support, +specifically for L, and may be changed in +the future. + =head2 _send_to_log $log->_send_to_log( @messages ); @@ -301,6 +317,10 @@ the right place. If the environment has a C, it will be used. If not, we will send logs to C if that exists. As a last fallback, we will send to STDERR as before. +=head2 clear_psgi + +Clears the PSGI environment attributes set by L. + =head2 meta =head1 SEE ALSO