lager icon indicating copy to clipboard operation
lager copied to clipboard

donot support "~tp" unicode encode

Open LittlePeng opened this issue 8 years ago • 9 comments

R16B2 support ~tp format term with utf8 binary as unicode:

erl +pc unicode
Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V7.0  (abort with ^G)
1> io_lib:format("~tp", [#{name=><<"测试中文"/utf8>>}]).
[[35,123,
  [["name"," => ",[60,60,"\"测试中文\"","/utf8>>"]]],
  125]]

but lager treat ~tp as ~p

lager:safe_format("~tp",[#{name=><<"测试中文"/utf8>>}], 1000).
["#{name => <<230,181,139,232,175,149,228,184,173,230,150,135>>}"]

LittlePeng avatar Mar 13 '16 07:03 LittlePeng

Hey I'm running into the same issue! Any idea why this is the case?

ssawan623 avatar Sep 01 '16 18:09 ssawan623

lager_trunc_io doesn't seem to support the t modifier to ~p - that's why it doesn't work.

jadeallenx avatar Sep 01 '16 20:09 jadeallenx

io_lib:format works because it's part of OTP - lager_trunc_io is a sort-of internal fork that cuts off output, but I think it was before there was a ~tp construction as part of OTP.

jadeallenx avatar Sep 01 '16 20:09 jadeallenx

Dup of #358

jadeallenx avatar Jan 20 '17 21:01 jadeallenx

@Vagabond I spent a few hours today looking at this issue, thinking about a newer "modern" replacement for trunc_io. I was pleased to see that https://github.com/erlang/otp/blob/master/lib/stdlib/src/io_lib_pretty.erl supports a maximum number of characters already (this is specifically around supporting "~tp" as a format string) and I'm wondering how safe it would be to just jncorporate that code.

I guess it wouldn't do the special formatting for records and stacktraces, but we could always special case that stuff I suppose.

jadeallenx avatar Apr 26 '17 21:04 jadeallenx

I am open to exploring this.

Vagabond avatar Apr 26 '17 22:04 Vagabond

So #417 doesn't fix the original problem where the data's encoded as a binary string but, it does work correctly here:

4> lager:log(info, self(), "测试中文").         
16:56:11.491 [info] 测试中文

So seems like there's still an issue with binary UTF8.

jadeallenx avatar Oct 19 '17 21:10 jadeallenx

Hello, was there any progress related to this problem?

Kintull avatar Sep 11 '18 08:09 Kintull

No, not since the last update on this ticket. Sorry.

jadeallenx avatar Sep 11 '18 15:09 jadeallenx