log4j2 无法按天切割_Log4j2故障转移无法按预期工作

Hello Community!

I have a problem using Apache's Log4j logging functionality.

The configuration file looks as follows:<?xmlversion ="1.0"encoding="UTF-8"?>

%d{yyyy-mm-dd HH:mm:ss.SSS} [%t] %-5level %C.%M(%F:%L) - %msg%n%throwable{full}

As seen, the primary logger shall write the information to a database table. This works fine.

The problem occurs when the logger cannot write to the database.

As I understand the "Failover" logger, it should use the "HDRollingFile" logger in this situation. But after the program has ended, the Log-file is still empty.

With the Configuration status="warn" level, I get the following error: ERROR appender Failover has no parameter that matches element Failovers

But this code is exactly like the code in the Log4j2 documentation.

The result is, the exceptions for the database not being accessible, are printed to the console, but none of my logging information I am generating in my program code.

Does anybody have a clue what is going on here and how to fix it?

Thanks in advance. :)

解决方案I have the exact same problem, and I believe we are not alone. I see very strange behaviour, wherein my integration test, which uses an identical classpath (except the additional testing libs), does NOT throw this error and so failover works. So, my integration tests pass but when I run my code from my main() method, the log4j2 config throws this lame error.

I've tried re-ordering my elements but according to the documentation, the way you have them listed is correct. If I had to guess, there is a race condition in the config manager that tries to initialize the failover appender before it's instantiated. Why this doesn't happen in my integration tests, I don't know. It's a real time sucker to track down and this behaviour is critical to my application.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值