Description
The attached example outputs a short string containing non-ascii characters ("Schöner Spaß") both to System.out and via log4j2 to a ConsoleAppender with target SYSTEM_OUT.
When I run the example in my IDE, it outputs the string correctly both times, as expected
However, if I run the example in a console on my Windows Desktop (10.0), only the output to System.out is correct. The non-ascii-characters get broken in the output of log4j2.
I know that a workaround is to add charset="IBM850" in the PatternLayout, but this clearly causes problems if the application runs in a different environment.
I definitely expect that log4j uses the platform default encoding, just as System.out does, and this seems to be other peoples' expectation, too. See e.g. LOG4J2-2929, stating incorrectly that "Currently PatternLayout always uses the default charset if none is specified explicitly."
Another workaround is, of course, to specify a certain encoding (e.g. UTF-8) both for System.out and for the PatternLayout and to require the user to set the windows codepage (using e.g. CHCP 65001). I dislike that approach because it defeats the purpose of the "platform default encoding" and places a burden on the user
Attachments
Attachments
Issue Links
- is related to
-
LOG4J2-783 PatternLayout's default charset should not be UTF-8
- Resolved
-
LOG4J2-1636 Console Appender does not pick up Oracle Java 8's sun.stdout.encoding and sun.stderr.encoding
- Resolved