Plack::Middleware::LogStderr - Everything printed to STDERR sent to psgix.logger or other logger
version 0.001
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"; }; ...
This middleware intercepts all output to stderr and redirects it to a defined logger.
stderr
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.
One 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.
STDERR
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.
system
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.
psgix.logger
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
tie_callback
capture_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.
PSGI::Extensions - the definition of psgix.logger
Plack::Middleware::LogDispatch - use a Log::Dispatch logger for psgix.logger
Plack::Middleware::Log4perl - use a Log::Log4perl logger for psgix.logger
Capture::Tiny
"The Error Stream" in PSGI - the definition of psgi.errors
psgi.errors
Plack::Middleware::LogErrors - redirect psgix.error to psgix.logger
psgix.error
The source code repository for Plack-Middleware-LogStderr can be found at https://github.com/amalek215/Plack-Middleware-LogStderr
Alex Malek <amalek@cpan.org>
Karen Etheridge
Alex Malek
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.
To install Plack::Middleware::LogStderr, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::LogStderr
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::LogStderr
For more information on module installation, please visit the detailed CPAN module installation guide.