Log4j2的编码问题[英] Log4j2 encoding issue

本文是小编为大家收集整理的关于Log4j2的编码问题的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

当我尝试在Windows 10上运行Elasticsearch,因为主要语言是英语,一切正常.但是,如果我将主要语言更改为土耳其语,我会收到错误消息,例如:

2018-07-26 14:42:39,485 main ERROR Unable to locate plugin type for IfFileName
2018-07-26 14:42:39,633 main ERROR Unable to locate plugin for IfAccumulatedFileSize
2018-07-26 14:42:39,634 main ERROR Unable to locate plugin for IfFileName
2018-07-26 14:42:39,637 main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.rolling.action.DeleteAction for element Delete: java.lang.NullPointerException java.lang.NullPointerException
    at org.apache.logging.log4j.core.config.plugins.visitors.PluginElementVisitor.findNamedNode(PluginElementVisitor.java:103)
    at org.apache.logging.log4j.core.config.plugins.visitors.PluginElementVisitor.visit(PluginElementVisitor.java:87)
    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.generateParameters(PluginBuilder.java:248)
    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:135)
    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.createConfiguration(AbstractConfiguration.java:890)
    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.start(LoggerContext.java:261)
    at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:163)
    at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:119)
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:291)
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121)
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112)
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124)
    at org.elasticsearch.cli.Command.main(Command.java:90)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85)

2018-07-26 14:42:39,645 main ERROR Null object returned for Delete in DefaultRolloverStrategy.

因此,这似乎是一个charset问题.该文件编码为UTF-8,我使用记事本++进行检查. Elasticsearch具有JVM选项-Dfile.encoding=UTF-8.我仔细检查了log4j2.properties文件,IfFileName没有空间.

,如果我更改IfFileName为ıfFileName(ı是土耳其字符 - 较低i)错误变为:

2018-07-26 14:54:25,819 main ERROR Unable to locate plugin type for ıfFileName

有人知道如何解决这个问题吗?

推荐答案

添加-Duser.language=en JVM参数已解决问题.

其他推荐答案

我遇到了相同的问题(它发生在我使用elasticsearch的Sonarqube安装中.),但不知道在哪里添加-Duser.language=en.但是,我发现它是在声纳的下方.

其他推荐答案

这是log4j2中的一个错误,它使用 String#toLowerCase() 没有区域参数:在土耳其语言环境中,IfFileName在ıffilename(带有无用的I i i i i i i i) ).我已将其报道为 gh问题#1281 .

在修复此操作之前,您可以在所有小写字母(英语)字母中编写插件类型:例如iffilename而不是IfFileName.

本文地址:https://www.itbaoku.cn/post/1575129.html

问题描述

When I try to run Elasticsearch on Windows 10 as main language is English, everything works fine. But if I change the main language as Turkish, I get error messages as:

2018-07-26 14:42:39,485 main ERROR Unable to locate plugin type for IfFileName
2018-07-26 14:42:39,633 main ERROR Unable to locate plugin for IfAccumulatedFileSize
2018-07-26 14:42:39,634 main ERROR Unable to locate plugin for IfFileName
2018-07-26 14:42:39,637 main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.rolling.action.DeleteAction for element Delete: java.lang.NullPointerException java.lang.NullPointerException
    at org.apache.logging.log4j.core.config.plugins.visitors.PluginElementVisitor.findNamedNode(PluginElementVisitor.java:103)
    at org.apache.logging.log4j.core.config.plugins.visitors.PluginElementVisitor.visit(PluginElementVisitor.java:87)
    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.generateParameters(PluginBuilder.java:248)
    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:135)
    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.createConfiguration(AbstractConfiguration.java:890)
    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.start(LoggerContext.java:261)
    at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:163)
    at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:119)
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:291)
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121)
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112)
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124)
    at org.elasticsearch.cli.Command.main(Command.java:90)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85)

2018-07-26 14:42:39,645 main ERROR Null object returned for Delete in DefaultRolloverStrategy.

So it seem like a charset problem. The file is encoded as UTF-8, I check it with Notepad++. Elasticsearch has JVM option -Dfile.encoding=UTF-8. I double checked the log4j2.properties file and IfFileName has no space after it.

And if I change IfFileName as ıfFileName (which ı is a Turkish character - lower I) error becomes:

2018-07-26 14:54:25,819 main ERROR Unable to locate plugin type for ıfFileName

Does anyone have an idea about how to fix that?

推荐答案

Adding -Duser.language=en JVM parameter fixed the problem.

其他推荐答案

I had the same problem (it happened in the sonarqube installation for me which uses elasticsearch.) but didn't know where to add the -Duser.language=en. However, I found it out it is under the sonar.properties, the line where sonar.search.javaAdditionalOpts= is located remove the # at the begining and write as sonar.search.javaAdditionalOpts=-Duser.language=en and save the file.

其他推荐答案

This is a bug in Log4j2, which uses String#toLowerCase() without a locale parameter: in the Turkish locale IfFileName is lowercased as ıffilename (with a dotless i). I have reported this as GH issue #1281.

Until this is fixed you can write plugin types in all lowercase (English) letters: e.g. iffilename instead of IfFileName.