log4cxx-0.10.0 Log Chinese garbled

Source: Internet
Author: User

log4cxx-0.10.0 Log Chinese garbled

(Jin Qing's column)

Log4cxx upgrade to 0.10.0, found that the Chinese output is garbled.
In fact, it should be Chinese into a question mark, not garbled.

The question mark in Logcxx indicates that the characters in the codec process are missing.
enum {Losschar = 0x3F};
If the Chinese is decoded in ASCII, because the character is greater than 0x80, it will be turned into a question mark.

Modify the method to enter the log4cxx-0.10.0 directory,
sudo make install
(Reference: http://cooling.ape-tech.com/bbs/thread-2084-1-1.html)

There are two macro definitions in log4cxx that correspond to these two options:
Log4cxx_logchar_is_utf8 indicates that the Logcxx logstring inner code is UTF-8.
The inner code may also be wchar_t or UTF-16.
Log4cxx_charset_utf8 indicates that the character set is UTF-8.
If both are utf8, then there is no need to codec.

Another option is to fix an error in Transcoder::encodecharsetname ().
The offset of the displayed characters in the ASCII table is 0x20, not 0x30.
This error will cause all Aprcharsetdecoder and aprcharsetencoder to fail.
The error has been fixed on the code skeleton.

You may also need to set up locale in your application:
SetLocale (Lc_all, "zh_cn.") GB2312 ");
On my machine, Somehow, Nl_langinfo (codeset) returns ansi_x3.4-1968 by default,
So must hand setlocale (), otherwise log4cxx will be the Chinese log ansi_x3.4-1968 decoding,
The result will become a string of question marks.

If you need to specify the character encoding for the output, you can:
Appender->setencoding ("GB2312");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.