gpt4 book ai didi

properties - 我无法配置具有多个条件的 log4j2 属性文件

转载 作者:行者123 更新时间:2023-12-03 18:15:18 25 4
gpt4 key购买 nike

我是 Elasticsearch 用户,我必须使用 log4j2.properties 文件。
不幸的是,我无法按照自己的意愿删除日志。

我想要一些日志文件(对应于一个模式)每天轮换。
如果轮换的日志文件符合我的两个条件之一,我还希望将其删除:

  • 如果他们超过 3 个月大
  • 如果这些文件的总大小超过 200 兆。

  • 我尝试使用 PathCondition "ifany",在这段 log4j2 文档中描述:
    https://logging.apache.org/log4j/2.x/manual/appenders.html

    这是我的 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}.log
    appender.rolling.layout.type = PatternLayout
    appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%.-10000m%n
    appender.rolling.filePattern = ${sys:es.logs}-%d{yyyy-MM-dd}.log
    appender.rolling.policies.type = Policies
    appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
    appender.rolling.policies.time.interval = 1
    appender.rolling.policies.time.modulate = true
    appender.rolling.strategy.type = DefaultRolloverStrategy
    appender.rolling.strategy.action.type = Delete
    appender.rolling.strategy.action.basepath = /var/log/elasticsearch
    appender.rolling.strategy.action.condition.type = IfFileName
    appender.rolling.strategy.action.condition.glob = mylog-*.log
    appender.rolling.strategy.action.PathConditions.type = IfAny
    appender.rolling.strategy.action.PathConditions.nestedConditions.type = IfLastModified
    appender.rolling.strategy.action.PathConditions.nestedConditions.age = 90D
    appender.rolling.strategy.action.PathConditions.nestedConditions.type = IfAccumulatedFileSize
    appender.rolling.strategy.action.PathConditions.nestedConditions.exceeds = 200M

    目前,当我重新启动 log4j2 时,我收到错误消息:

    main ERROR IfAccumulatedFileSize contains an invalid element or attribute "age"



    我真的很感激在这个问题上的任何帮助。感谢您的关注!

    最佳答案

    尝试更改 DeleteAction 的配置如下所示 -

    appender.rolling.strategy.type = DefaultRolloverStrategy
    appender.rolling.strategy.action.type = Delete
    appender.rolling.strategy.action.basepath = /var/log/elasticsearch
    appender.rolling.strategy.action.maxDepth = 1
    appender.rolling.strategy.action.condition.type = IfFileName
    appender.rolling.strategy.action.condition.glob = mylog-*.log
    appender.rolling.strategy.action.ifAny.type = IfAny
    appender.rolling.strategy.action.ifAny.ifLastModified.type = IfLastModified
    appender.rolling.strategy.action.ifAny.ifLastModified.age = 90d
    appender.rolling.strategy.action.ifAny.ifAccumulatedFileSize.type = IfAccumulatedFileSize
    appender.rolling.strategy.action.ifAny.ifAccumulatedFileSize.exceeds = 200MB

    您也可以引用 log4j2 documentation用于配置多个条件。 Log4j2文档描述了 XML 配置。但是,通过引用这些示例,您也可以思考和猜测属性配置。

    关于properties - 我无法配置具有多个条件的 log4j2 属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48443137/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com