logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: How to write Asian character to file?
Date Tue, 28 Feb 2006 19:17:46 GMT

On Feb 28, 2006, at 5:11 AM, Ken wrote:

>   What is right syntax if I want use char array variable with wide  
> character?
>         char  lc_str[] =  "hello你好hello01";
>         logstream << lc_str << LOG4CXX_ENDMSG;  // not work
>   since L only can use with literal.
>  a fool question, but I just can not figure it out. Hope somebody  
> will tell me.

        const wchar_t  lc_str[] =  L"hello你好hello01";

There is a unit test for encoding support (tests/src/ 
encodingtest.cpp) that should be run as part of the Ant build.   Did  
the unit tests pass on your platform?

What happens if you try to output the test string from the unit test:

         //   arbitrary, hopefully meaningless, characters from
         //     Latin, Arabic, Armenian, Bengali, CJK and Cyrillic
         const wchar_t greeting[] = { L'A', 0x0605, 0x0530, 0x986,  
0x4E03, 0x400, 0 };

If that works, I'd suspect that there is a mismatch between source  
file encoding and the encoding expectations of your compiler.  For  
example, your source file might be in UTF-8 and the compiler expects  
ISO-8859-1.  The string in the unit test would not be affected be an  
source file encoding mismatch.

You mentioned that your LANG is "en_US".  Plain en_US on other Linux  
distributions indicates ISO-8859-1 as the default encoding  where  
en_US.UTF-8 would indicate UTF-8 as the default encoding.  ISO-8859-1  
can not represent Asian characters and log4cxx will substitute '?'  
for any character it can not represent in the current encoding.   
Seeing '?' in the output would be the expected (and desirable)  
behavior if the encoding is ISO-8859-1.

What happens if you set the LANG environment variable to en_US.UTF-8  
before running the program?  What happens if you explicitly call  
setEncoding("UTF-8") on the appender?

View raw message