You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2022/02/01 15:35:00 UTC

[jira] [Comment Edited] (LOG4J2-3372) ConsoleAppender on Windows does not use platform default encoding

    [ https://issues.apache.org/jira/browse/LOG4J2-3372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17484742#comment-17484742 ] 

Gary D. Gregory edited comment on LOG4J2-3372 at 2/1/22, 3:34 PM:
------------------------------------------------------------------

It seems a console appender should specify its PatternLayout charset unless the PatternLayout defines it explicitly.
This means our building framework needs access to a parent object when building a child, in this case, the pattern layout would need to access the console appender, but that is not how the configuration runs at all. Needs further investigation. Otherwise, we need to document the Console Appender to ALWAYS configure its layout with a charset.



was (Author: garydgregory):
It seems a console appender should specify its PatternLayout charset unless the PatternLayout defines it explicitly.


> ConsoleAppender on Windows does not use platform default encoding
> -----------------------------------------------------------------
>
>                 Key: LOG4J2-3372
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3372
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.17.1
>            Reporter: Oliver Matz
>            Priority: Minor
>         Attachments: ConsoleEncodingExample.java, LOG4J2-3372-sceenshot.png, log4j2.xml
>
>
> 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



--
This message was sent by Atlassian Jira
(v8.20.1#820001)