Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-3372

ConsoleAppender on Windows does not use platform default encoding

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.17.1
    • None
    • Appenders
    • None

    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

        1. LOG4J2-3372-sceenshot.png
          11 kB
          Oliver Matz
        2. log4j2.xml
          0.5 kB
          Oliver Matz
        3. ConsoleEncodingExample.java
          0.6 kB
          Oliver Matz

        Issue Links

          Activity

            People

              pkarwasz Piotr Karwasz
              o.matz Oliver Matz
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: