houseabsolute / Log-Dispatch

Dispatches messages to one or more outputs
https://metacpan.org/release/Log-Dispatch/
Other
12 stars 29 forks source link

Log::Dispatch::Screen doesn't write to fd 1 or 2 as documented #66

Closed mauke closed 1 year ago

mauke commented 1 year ago

https://metacpan.org/release/DROLSKY/Log-Dispatch-2.70/view/lib/Log/Dispatch/Screen.pm says:

this module opens it's own handle to fd 1 or 2 instead of using the global STDOUT or STDERR

Therefore I should be able to send STDOUT/STDERR elsewhere and still use my logger object (as long as file descriptors 1 and 2 are set correctly). But this doesn't work:

use strict;
use warnings;
use Log::Dispatch;

my $log = Log::Dispatch->new(
    outputs => [
        [
            'Screen',
            min_level => 'debug',
            newline   => 1,
            stderr    => 0,
        ],
    ],
);

open my $null, '>', '/dev/null' or die "$0: /dev/null: $!\n";
open my $fd_1, '>&=', 1 or die "$0: can't fdopen 1: $!\n";
*STDOUT = *$null{IO};

print STDOUT "I don't see this\n";
print $fd_1 "this is all right\n";

$log->warning("I should see this");

Actual output:

$ perl try.pl
this is all right

Expected output:

$ perl try.pl
this is all right
I should see this
autarch commented 1 year ago

It looks like I had to revert this behavior but I forgot to change the docs. I will fix them.

autarch commented 1 year ago

Thanks for the bug report! The docs have been fixed in v2.71.