Coder Social home page Coder Social logo

manwar / plack-middleware-logstderr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from amalek215/plack-middleware-logstderr

0.0 3.0 0.0 14 KB

Plack middleware to redirect everything printed to STDERR to psgix.logger or other logger

License: Other

Perl 100.00%

plack-middleware-logstderr's Introduction

NAME

Plack::Middleware::LogStderr - Everything printed to STDERR sent to psgix.logger or other logger

VERSION

version 0.001

SYNOPSIS

Using a logger you have already configured (using Log::Dispatch as an example):

use Log::Dispatch;
my $logger = Log::Dispatch->new;
$logger->add( Log::Dispatch::File->new(...) );

builder {
    enable 'LogDispatch', logger => $logger;
    enable 'LogStderr';
    $app;
}

Using an explicitly defined logger:

builder {
    enable 'LogStderr', logger => sub {
        my $args = shift;
        $logger->log(%$args);
    };
    $app;
}

Other Options:

...
enable 'LogStderr',
    log_level => 'warn',
    no_tie => 1,
    callback => sub {
        my $msg = shift;
        return "STDERR:$msg\n";
};
...

DESCRIPTION

This middleware intercepts all output to STDERR and redirects it to a defined logger.

Examples where STDERR output would not typically be sent to a logger:

print STDERR "foo";
system('perl -e " print STDERR \'bar\'"');
warnings::warn("baz");

This middleware uses two techniques to catch messages sent to STDERR and direct them to a logger.

The first ties the STDERR filehandle and directs all print messages to a logger. This method only works if the code printing to STDERR is aware of the Perl tied filehandle.

The second technique uses Capture::Tiny to capture everything else written to STDERR (for example any programs run using system). This method groups all STDERR output into one message. The drawback here is log messages may not be interleaved temporally with messages generated from the tied method or other calls to the logger.

NAME

Plack::Middleware::LogStderr - redirect STDERR output to a defined logger

CONFIGURATION

logger

A code reference for logging messages, that conforms to the psgix.logger specification. If not provided, psgix.logger is used, or the application will generate an error at runtime if there is no such logger configured.

log_level, log_level_capture

By default the log level used is 'error' use log_level to set it to another value.

Use log_level_capture if you want the default log level for captured output to be different from log_level

Make sure the log level used is valid for your logger!

callback, capture_callback, tie_callback

Callbacks that take a string and return a string.

callback is applied to all messages.
capture_callback is applied to all messages logged via the capture method.
tie_callback is applied to messages logged via the tied STDERR filehandle.

no_tie

Do not tie the perl file handle STDERR to a logger. When set, all output to STDERR will be caught and logged in one message.

The benefit of this is all output sent to STDERR is in order. The drawback is all STDERR output created during a request is grouped together as one message and logged together after the request has finished processesing.

SEE ALSO

ACKNOWLEDGEMENTS

Karen Etheridge

SOURCE

The source code repository for Plack-Middleware-LogStderr can be found at https://github.com/amalek215/Plack-Middleware-LogStderr

AUTHOR

Alex Malek <[email protected]>

AUTHOR

Alex Malek

COPYRIGHT AND LICENSE

This software is copyright (c) 2018 by Alex Malek.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

plack-middleware-logstderr's People

Contributors

amalek215 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.