You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@logging.apache.org by "Frank Steudle (JIRA)" <ji...@apache.org> on 2017/09/20 11:07:00 UTC

[jira] [Comment Edited] (LOG4J2-1888) Log4j throws a java.nio.charset.UnsupportedCharsetException: cp65001

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

Frank Steudle edited comment on LOG4J2-1888 at 9/20/17 11:06 AM:
-----------------------------------------------------------------

Today I updated my fitnesse project to use the 2.9.0 versions of log4-core and log4j-api. Now I am encountering the above mentioned exception. I am using ISO-8859-1 on my Eclipse computer to store the files. But the execution environment is plain UTF-8. Therefore I am using those parameters to run my fitnesse project:

* -Dsun.jnu.encoding=UTF8: handed over as JAVA_TOOL_OPTIONS
* -Dfile.encoding=UTF8: handed over as JAVA_TOOL_OPTIONS
* chcp 65001: to switch the Windows console encoding to UTF8

Here is the exception, which is thrown: 


{code:java}
C:\Users\admin\Desktop\RabbitDevInstall\Testtool>java -jar RunRabbitRun-2.0-SNAPSHOT-jar-with-dependencies.jar start ./Resources
Picked up JAVA_TOOL_OPTIONS: -Dsun.jnu.encoding=UTF8 -Dfile.encoding=UTF8 -Ds=0
Unable to get Charset 'sun.stdout.encoding', using default UTF-8
java.nio.charset.UnsupportedCharsetException: cp65001
        at java.nio.charset.Charset.forName(Unknown Source)
        at org.apache.logging.log4j.util.PropertiesUtil.getCharsetProperty(PropertiesUtil.java:172)
        at org.apache.logging.log4j.core.appender.ConsoleAppender$Target.getCharset(ConsoleAppender.java:89)
        at org.apache.logging.log4j.core.appender.ConsoleAppender$Target$1.getDefaultCharset(ConsoleAppender.java:74)
        at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.build(ConsoleAppender.java:222)
        at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.build(ConsoleAppender.java:189)
        at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:958)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:898)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:890)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:513)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:237)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:249)
        at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:617)
        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
        at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
        at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
        at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:551)
        at de.duerr.fitnesse.RunRabbitRun.<clinit>(RunRabbitRun.java:24)
11:37:19.176 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - Passed over first parameter: start
11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - Passed over Fitnesse directory: ./Resources
11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - The parameters handed over to Fitnesse: -d
11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - The parameters handed over to Fitnesse: ./Resources
11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - The parameters handed over to Fitnesse: -r
11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - The parameters handed over to Fitnesse: FitNesseRoot
Sep 20, 2017 11:37:19 AM fitnesse.ConfigurationParameter loadProperties
INFORMATION: No configuration file found (C:\Users\admin\Desktop\RabbitDevInstall\Testtool\Resources\plugins.properties)
Bootstrapping FitNesse, the fully integrated standalone wiki and acceptance testing framework.
root page: fitnesse.wiki.fs.WikiFilePage: FitNesseRoot
logger: none
authenticator: fitnesse.authentication.PromiscuousAuthenticator
page factory: fitnesse.html.template.PageFactory
page theme: bootstrap
Starting FitNesse on port: 80
{code}

However, my project is running well. Seems to work anyway.

Here is my log4j configuration file:


{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
    
    <RollingFile name="RollingFile" fileName="logs/rrr.log"
                 filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log">
      <PatternLayout>
        <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
      </PatternLayout>
      <Policies>
        <TimeBasedTriggeringPolicy />
        <OnStartupTriggeringPolicy />
        <SizeBasedTriggeringPolicy size="20 MB"/>
      </Policies>
    </RollingFile>
    
  </Appenders>
  <Loggers>
    <Root level="all">
      <AppenderRef ref="RollingFile"/>
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>
{code}

And here is my starting script:

{code:java}
SET RRR_RESOURCES=.

SET JAVA_TOOL_OPTIONS=-Dsun.jnu.encoding=UTF8 -Dfile.encoding=UTF8 -Ds=0

chcp 65001

java -version

java -XshowSettings

java -jar ${project.artifactId}-${project.version}-jar-with-dependencies.jar start ./Resources

{code}



was (Author: steudle.f@duerr.de):
Today I updated my fitnesse project to use the 2.9.0 versions of log4-core and log4j-api. Now I am encountering the above mentioned exception. I am using ISO-8859-1 on my Eclipse computer to store the files. But the execution environment is plain UTF-8. Therefore I am using those parameters to run my fitnesse project:

* -Dsun.jnu.encoding=UTF8: handed over as JAVA_TOOL_OPTIONS
* -Dfile.encoding=UTF8: handed over as JAVA_TOOL_OPTIONS
* chcp 65001: to switch the Windows console encoding to UTF8

Here is the exception, which is thrown: 


{code:java}
C:\Users\admin\Desktop\RabbitDevInstall\Testtool>java -jar RunRabbitRun-2.0-SNAPSHOT-jar-with-dependencies.jar start ./Resources
Picked up JAVA_TOOL_OPTIONS: -Dsun.jnu.encoding=UTF8 -Dfile.encoding=UTF8 -Ds=0
Unable to get Charset 'sun.stdout.encoding', using default UTF-8
java.nio.charset.UnsupportedCharsetException: cp65001
        at java.nio.charset.Charset.forName(Unknown Source)
        at org.apache.logging.log4j.util.PropertiesUtil.getCharsetProperty(PropertiesUtil.java:172)
        at org.apache.logging.log4j.core.appender.ConsoleAppender$Target.getCharset(ConsoleAppender.java:89)
        at org.apache.logging.log4j.core.appender.ConsoleAppender$Target$1.getDefaultCharset(ConsoleAppender.java:74)
        at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.build(ConsoleAppender.java:222)
        at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.build(ConsoleAppender.java:189)
        at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:958)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:898)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:890)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:513)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:237)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:249)
        at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:617)
        at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
        at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
        at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
        at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:551)
        at de.duerr.fitnesse.RunRabbitRun.<clinit>(RunRabbitRun.java:24)
11:37:19.176 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - Passed over first parameter: start
11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - Passed over Fitnesse directory: ./Resources
11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - The parameters handed over to Fitnesse: -d
11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - The parameters handed over to Fitnesse: ./Resources
11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - The parameters handed over to Fitnesse: -r
11:37:19.192 [main] DEBUG de.duerr.fitnesse.RunRabbitRun - The parameters handed over to Fitnesse: FitNesseRoot
Sep 20, 2017 11:37:19 AM fitnesse.ConfigurationParameter loadProperties
INFORMATION: No configuration file found (C:\Users\admin\Desktop\RabbitDevInstall\Testtool\Resources\plugins.properties)
Bootstrapping FitNesse, the fully integrated standalone wiki and acceptance testing framework.
root page: fitnesse.wiki.fs.WikiFilePage: FitNesseRoot
logger: none
authenticator: fitnesse.authentication.PromiscuousAuthenticator
page factory: fitnesse.html.template.PageFactory
page theme: bootstrap
Starting FitNesse on port: 80
{code}

However, my project is running well. Seems to work anyway.

Here is my log4j configuration file:


{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
    
    <RollingFile name="RollingFile" fileName="logs/rrr.log"
                 filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log">
      <PatternLayout>
        <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
      </PatternLayout>
      <Policies>
        <TimeBasedTriggeringPolicy />
        <OnStartupTriggeringPolicy />
        <SizeBasedTriggeringPolicy size="20 MB"/>
      </Policies>
    </RollingFile>
    
  </Appenders>
  <Loggers>
    <Root level="all">
      <AppenderRef ref="RollingFile"/>
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>
{code}


> Log4j throws a java.nio.charset.UnsupportedCharsetException: cp65001
> --------------------------------------------------------------------
>
>                 Key: LOG4J2-1888
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1888
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.8.2
>            Reporter: Misagh Moayyed
>             Fix For: 2.9.0
>
>
> Running a Java spring boot web application using a "java -jar" type of command with a pretty vanilla log4j2.xml file in it, I see the following error. 
> {code}
> 2017-04-24 11:47:45,338 main ERROR Unable to inject fields into builder class for plugin type class org.apache.logging.log4j.core.appender.ConsoleAppender, element Console. java.nio.charset.UnsupportedCharsetException: cp65001
>         at java.nio.charset.Charset.forName(Charset.java:531)
>         at org.apache.logging.log4j.util.PropertiesUtil.getCharsetProperty(PropertiesUtil.java:146)
>         at org.apache.logging.log4j.util.PropertiesUtil.getCharsetProperty(PropertiesUtil.java:134)
>         at org.apache.logging.log4j.core.appender.ConsoleAppender$Target.getCharset(ConsoleAppender.java:85)
>         at org.apache.logging.log4j.core.appender.ConsoleAppender$Target$1.getDefaultCharset(ConsoleAppender.java:71)
>         at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.build(ConsoleAppender.java:218)
>         at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.build(ConsoleAppender.java:185)
>         at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
>         at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:952)
>         at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:892)
>         at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:884)
>         at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:508)
>         at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:232)
>         at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:244)
> {code}
> I am running the "run" command on Windows 10 64x inside a ConEmu console. If I switch to Babun, then I don't see the error. 
> This may not exactly be a "bug", but it would be great to not crash the app and fallback to a more accepting encoding perhaps. 



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)