当前位置: 首页 > 知识库问答 >
问题:

对log4j2的更改。属性文件导致elasticsearch失败

印成天
2023-03-14

我已经安装了elasticsearch(6.6.0)和CentOS 7。我想为旋转日志添加更多属性,比如大小为50MB的旋转和压缩。但如果我在/etc/elasticsearch/log4j2中添加更多配置。属性文件并重新启动elasticsearch服务器,则失败。

我当前的log4j2.properties文件:

status = error

# log action execution errors for easier debugging
logger.action.name = org.elasticsearch.action
logger.action.level = debug

appender.console.type = Console
appender.console.name = console
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%m%n

appender.rolling.type = RollingFile
appender.rolling.name = rolling
appender.rolling.fileName = 
${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] 
%marker%.-10000m%n
appender.rolling.filePattern = 
${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-
%d{yyyy-MM-dd}-%i.log.gz    
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true

rootLogger.level = info
rootLogger.appenderRef.console.ref = console
rootLogger.appenderRef.rolling.ref = rolling

当我尝试添加,因为它是在elasticsearch文档这是如何添加配置,

appender.rolling.policies.size.size = 2MB
appender.rolling.strategy.action.condition.age = 3D
appender.rolling.strategy.action.type = Delete
appender.rolling.strategy.action.condition.type = IfFileName

它是错误的失败:

Exception in thread "main" org.apache.logging.log4j.core.config.ConfigurationException: No type attribute provided for component size
    at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.createComponent(PropertiesConfigurationBuilder.java:333)
    at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.processRemainingProperties(PropertiesConfigurationBuilder.java:347)
    at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.createComponent(PropertiesConfigurationBuilder.java:336)
    at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.processRemainingProperties(PropertiesConfigurationBuilder.java:347)
    at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.createAppender(PropertiesConfigurationBuilder.java:224)
    at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.build(PropertiesConfigurationBuilder.java:157)
    at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:56)
    at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:35)
    at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:244)
    at org.elasticsearch.common.logging.LogConfigurator$1.visitFile(LogConfigurator.java:105)
    at org.elasticsearch.common.logging.LogConfigurator$1.visitFile(LogConfigurator.java:101)
    at java.nio.file.Files.walkFileTree(Files.java:2670)
    at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:101)
    at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:84)
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:316)
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123)
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114)
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67)
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122)
    at org.elasticsearch.cli.Command.main(Command.java:88)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84)

我在 /var/log/elasticsearch/elasticsearch_deprecation.log有一个警告:

[2018-02-20T02:09:32,694][WARN ][o.e.d.e.NodeEnvironment  ] ES has detected the [path.data] folder using the cluster name as a folder [/data/es], Elasticsearch 6.0 will not allow the cluster name as a folder within the data path

有人能解释一下如何将配置添加到log4j2吗。属性文件?

共有1个答案

史鹏云
2023-03-14

正如日志所述,您缺少大小配置的类型属性。您还缺少RolloverStrategytype属性。

试试下面的配置-

appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size = 2 MB

appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.action.type = Delete
appender.rolling.strategy.action.basePath = ${sys:es.logs.base_path}${sys:file.separator}
appender.rolling.strategy.action.maxDepth = 1
appender.rolling.strategy.action.ifLastModified.type = IfLastModified
appender.rolling.strategy.action.ifLastModified.age = 3d
 类似资料:
  • HTTP头所在的位置 现在在Spring 5上-这被更改为 现在头从-{accept=[application/json],content-type=[multipart/form-data;boundary=8hfyfdj_y58snxrsdxenwliqdsyixs50],content-length=[51024]} 我搜索了很多,发现了一个类似的问题,这似乎更密切相关--升级到Spring

  • 问题内容: 我希望使用该类来更改Java中文件的时间戳记元数据。 我想更改所有3个Linux / ext4时间戳(最后修改,访问和更改)。 我可以按如下方式更改前两个时间戳字段: 但是,我无法修改文件的最后一次 更改: 时间。同样,值得关注的是文档中没有提到更改时间戳。最接近的可用属性是,我尝试没有成功。 关于如何根据Java中的自定义时间戳修改文件元数据的任何想法? 谢谢! 问题答案: 我可以使

  • 例如:如果jar文件位于“D:\apps\jar.jar”中,则日志路径为“D:\log”;如果jar文件位于“C:\apps\jar.jar”中,则日志路径为“C:\log” 我尝试将log4j2.xml中的行(如下)更改为: 并在初始化记录器之前调用此函数:

  • 我有一个版本1.0的应用程序,它的项目目标是android-10。属性文件。它已成功构建并上载到playstore。。。 现在我升级到2.0版本,项目目标改为android-13 现在,当我尝试在Playstore中更新apk时。。这给了我错误 “上载失败..无法保存更改..请重试” 我正在使用相同的包和密钥库。。。唯一的项目。属性生成目标已更改 清单文件仍然显示min-sdk-version=9

  • 我正在运行它正在运行命令来压缩目录。以下是的任务。 上面给出了以下错误。 “警告”:使用unArchive模块而不是运行tar stderr: tar:删除成员名称中的前导'/'tar: /home/ubuntu/my-folder/xyz.log:文件更改 我还尝试了选项<code>——忽略失败的读取 由于此任务位于其他任务之间,因此在此任务之后必须运行的任务将失败。 无序不会给模块提供代码。只