preaction / Log-Any

Simple, fast Perl logging API compatible with any logging system
Other
13 stars 19 forks source link

Unicode symbols #54

Closed denistex closed 7 years ago

denistex commented 7 years ago

Hi guys and thanks for the great module!

I have a question for you and I can't found another way to ask you so probably this ticket is not an issue (sorry if so). I'm a newbie on Perl and I have Unicode problems all the time (I use Russian strings in my project). So here is my problem: I want to see Russian symbols in the log, but they looks like this: \x{41c}\x{43e}\x{451}. Is it possible to see valid symbols with your module? What should I do for that? Thanks in advance!

Here is how I'm using your modules:

package Log;

use strict;
use warnings;
use utf8;

use Log::Any ();
use Log::Any::Adapter ('Stdout');
use Log::Any::For::Std;

sub new {
    my ($class, $category) = @_;
    my $log = Log::Any->get_logger(category => $category // "general");
    my $self = {log => $log};
    bless $self, $class;
}

sub infof {
    my ($self, $message, @params) = @_;
    $self->{log}->infof($message, @params); # <-- $message has Russian symbols
}
preaction commented 7 years ago

I think the thing you need to do is to make sure that STDOUT is set to accept UTF-8, which you can do via this: http://perldoc.perl.org/perlunicook.html#%211e-15%3a-Declare-STD%7bIN%2cOUT%2cERR%7d-to-be-utf8

I'll leave this open to add a note to both the Stdout and Stderr adapters to recommend this for these situations.

denistex commented 7 years ago

Thanks for the answer!

Unfortunately configuring STDOUT didn't help me, so I continued research and found that Data::Dumper dumps data in that strange way. I googled around a bit and found great module named Data::Dumper::AutoEncode that solves my problem. I've written custom formatter using AutoEncode and it works like a charm now! :sunglasses:

So the issue is solved, thanks for your help and thanks @bayashi for useful module! :+1:

preaction commented 7 years ago

Ohhh! It's Data::Dumper doing it. Alright, I'll instead add a note about using that module in the case where you want to see those high-bit characters. Do you have an example of configuring a formatter that I can add to the docs?

denistex commented 7 years ago

Sure! I've created a gist for you.

I just realized that my first message is not correct (sorry about that) - $message variable doesn't contain Russian symbols actually, but @params do.

preaction commented 7 years ago

I added a TIPS section to Log::Any::Proxy with an example formatter that uses Data::Dumper::AutoEncode. Thanks for the sample code!