Search code examples
c++logginglog4cxx

Using utf-8 characters in log4cxx


I need to be able to use utf-8-encoded strings with log4cxx. I can print the strings just fine with std::cout (the characters are displayed correctly). Using log4cxx, i.e. putting the strings into the LOG4CXX_DEBUG() macro with a ConsoleAppender will output "??" instead of the special character. I found one solution:

LOG4CXX_DECODE_CHAR(logstring, str);
LOG4CXX_DEBUG(logstring);

where str is my input string, but this does not work. Anyone have an idea how this might work? I google'd around a bit, but I couldn't find anything useful.


Solution

  • You can use

    setlocale(LC_CTYPE, "UTF-8");
    

    to set only the character encoding, without changing any other information about the locale.