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 mangles Unicode text #67

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:

  • utf8 (0 or 1)

If this is true, then the output uses binmode to apply the :encoding(UTF-8) layer to the relevant handle for output.

Thus, if some other part of my code (or another module) already sets binmode $handle, ":encoding(UTF-8)", this should be a harmless no-op. But:

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

binmode STDOUT, ":encoding(UTF-8)";

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

$log->warning("caf\N{U+00E9}");

Actual output:

$ perl try.pl
café

Expected output:

$ perl try.pl
café
autarch commented 1 year ago

Since it's actually using STDOUT or STDERR in the hood, contrary to the docs, this is the expected outcome. I'll update the docs to note this potential double-encoding issue.

autarch commented 1 year ago

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