Catalyst::Plugin::LogWarnings - Log perl warnings to your Catalyst log object


Catalyst-Plugin-LogWarnings documentation Contained in the Catalyst-Plugin-LogWarnings distribution.

Index


Code Index:

NAME

Top

Catalyst::Plugin::LogWarnings - Log perl warnings to your Catalyst log object

VERSION

Top

Version 0.03

SYNOPSIS

Top

In MyApp.pm:

    use Catalyst qw/LogWarnings/;

After that, any warn statement that's executed during action processing is sent to the log $c-log> as a warning (instead of being dumped to STDERR).

Example:

    package MyApp::Controller::Foo;
    sub foo : Local() { warn 'foobar!'; }
    1;

Output (if you're using the standard Catalyst::Log logger):

    [info] MyApp running on Catalyst 5.7001
    [warn] foobar at Foo.pm line 2

CONFIGURATION

Top

None.

OVERRIDES

Top

execute

Wraps Catalyst::execute and catches warnings with a $SIG{__WARN__} statement.

AUTHOR

Top

Jonathan Rockway, <jrockway at cpan.org>

BUGS

Top

Warnings are caught after perl's rewritten them, so the line number and filename will be tacked on.

Please report any bugs or feature requests to bug-catalyst-plugin-logwarnings at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Plugin-LogWarnings. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Catalyst::Plugin::LogWarnings

You can also look for information at:

* Catalyst Project Homepage

http://www.catalystframework.org/

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Catalyst-Plugin-LogWarnings

* CPAN Ratings

http://cpanratings.perl.org/d/Catalyst-Plugin-LogWarnings

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-LogWarnings

* Search CPAN

http://search.cpan.org/dist/Catalyst-Plugin-LogWarnings

ACKNOWLEDGEMENTS

Top

#catalyst (irc://irc.perl.org/#catalyst).

COPYRIGHT & LICENSE

Top


Catalyst-Plugin-LogWarnings documentation Contained in the Catalyst-Plugin-LogWarnings distribution.
package Catalyst::Plugin::LogWarnings;

use warnings;
use strict;
use MRO::Compat;

our $VERSION = '0.03';

sub execute {
    my $c = shift;
    if(eval{$c->log->can('warn')}){
	    return do {
	        local $SIG{__WARN__} = sub {
		        my $warning = shift;
		        chomp $warning;
		        $c->log->warn($warning);
	        };
	        $c->next::method(@_);
	    };
    }
    else {
	    # warn "Can't log warnings";
	    # if we can't log warnings, don't catch them
	    return $c->next::method(@_);
    }
}

1; # End of Catalyst::Plugin::LogWarnings