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,
./configure--with-charset=utf-8--with-logchar=utf-8
Then
Make
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");