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

ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.ConsoleAppender for element Console:java.nio.charset.IllegalCharsetNameException: "file:/C:\test\log4j2.xml"

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Duplicate
    • 2.18.0
    • 2.19.0
    • None
    • None
    • windows 

    Description

      I have a test.bat file where I set -Dlog4j2.configurationFile to point to a valid log4j2.xml.

      This log4j2.xml has a console appender which is resulting in below exception.

      java.nio.charset.IllegalCharsetNameException:file:/C:\test\log4j2.xml
      at java.base/java.nio.charset.Charset.checkName(Charset.java:308)
      at java.base/java.nio.charset.Charset.lookup2(Charset.java:482)
      at java.base/java.nio.charset.Charset.lookup(Charset.java:462)
      at java.base/java.nio.charset.Charset.isSupported(Charset.java:503)
      at org.apache.logging.log4j.util.PropertiesUtil.getCharsetProperty(PropertiesUtil.java:215)

      Please note that same script file works fine in linux machine and I see this issue just in windows. If I replace log4j 2.18.0 with log4j 2.17.1 then I dont see any errors.

      After some basic debugging I got to know that normalized map under PropertiesUtil is not getting populated properly. All the properties in the map have log4j2.xml file path as value and thus the encoding property value in that map is set to log4j2.xml file path which is resulting in above exception.

      Below is my configuration for log4j2.xml.

      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration>
          <Appenders>
              <Console name="CONSOLE" target="SYSTEM_OUT">
                  <PatternLayout pattern="%-5p | %d{yyyy-MM-dd HH:mm:ss} | [%t] %C{2} (%F:%L) - %m%n" />
              </Console>
          </Appenders>
          <Loggers>
              <Logger name="com.test.package"
                  level="WARN" additivity="false">
                  <AppenderRef ref="CONSOLE" />    
              </Logger>
              <Root level="WARN">
                  <AppenderRef ref="CONSOLE" />
              </Root>
          </Loggers>
      </Configuration>

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              bsheri Bhavani Sheri
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: