ivanych / log-any-adapter-dupstd Goto Github PK
View Code? Open in Web Editor NEWCPAN module - Cunning adapter for logging to a duplicate of STDERR or STDOUT
License: Other
CPAN module - Cunning adapter for logging to a duplicate of STDERR or STDOUT
License: Other
В https://github.com/ivanych/Log-Any-Adapter-Dupstd/blob/master/lib/Log/Any/Adapter/Duperr.pm дублируется STDERR, соответственно открывается новый файловый хандлер с буфером.
Решить эту проблему можно так:
my $oldout = select $self->{fh};
$|=1;
select $oldout;
или
$self->{fh}->autoflush(1);
как указано в документации к перловым хандлерам: https://metacpan.org/pod/IO::Handle
This
package Log::Any::Adapter::Duperr;
#
# Cunning adapter for logging to a duplicate of STDERR
#
use 5.008001;
use strict;
use warnings;
use parent qw( Log::Any::Adapter::Stderr );
use Carp qw( croak );
our $VERSION = '0.05';
{
open my $fh, '>&', *STDERR or croak "Can't dup STDERR: $!"; ## no critic [InputOutput::RequireBriefOpen]
foreach my $method (Log::Any::Adapter::Util::logging_methods) {
my $parent_method = __PACKAGE__->can($method);
no strict 'refs'; ## no critic (ProhibitNoStrict)
*{$method} = sub {
local *STDERR = $fh;
$parent_method->(@_);
};
}
}
1;
is an alternative implementation of the Duperr adapter as an extension of the Stderr adapter. Unfortunately the implementation does not pass your unit tests because the tests are not implementation agnostic:
# irresponsible penetration into the object
my $adapter_fh = $log->{adapter}->{fh};
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.