gpt4 book ai didi

java - log4j 的生产设置文件?

转载 作者:太空狗 更新时间:2023-10-29 22:49:56 25 4
gpt4 key购买 nike

这是我当前的 log4j 设置文件。这些设置是否适合生产使用,或者我应该删除/调整或更改哪些设置?我问是因为我的所有线程都由于 log4j 阻塞而被挂起。我检查了打开的文件描述符,我只使用了 113。

# ***** Set root logger level to WARN and its two appenders to stdout and R.
log4j.rootLogger=warn, stdout, R

# ***** stdout is set to be a ConsoleAppender.
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
# ***** stdout uses PatternLayout.
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# ***** Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

# ***** R is set to be a RollingFileAppender.
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=logs/myapp.log
# ***** Max file size is set to 100KB
log4j.appender.R.MaxFileSize=102400KB
# ***** Keep one backup file
log4j.appender.R.MaxBackupIndex=5
# ***** R uses PatternLayout.
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %d %c - %m%n


#set httpclient debug levels
log4j.logger.org.apache.component=ERROR,stdout
log4j.logger.httpclient.wire=ERROR,stdout
log4j.logger.org.apache.commons.httpclient=ERROR,stdout
log4j.logger.org.apache.http.client.protocol=ERROR,stdout

更新***从我的所有线程中添加线程转储示例 (100)

"pool-1-thread-5" - Thread t@25
java.lang.Thread.State: BLOCKED on org.apache.log4j.spi.RootLogger@1d45a585 owned by: pool-1-thread-35
at org.apache.log4j.Category.callAppenders(Category.java:201)
at org.apache.log4j.Category.forcedLog(Category.java:388)
at org.apache.log4j.Category.error(Category.java:302)

最佳答案

Log4j 1.2 容易受到 deadlocks 的攻击当 toString() 产生嵌套日志时。

查看老年人仍 Unresolved 问题,如 Log4J can create deadlock conditions (concurrent package donation)Deadlock with RollingFileAppender .

它还存在在高并发负载下会导致性能下降的锁同步问题。喜欢Category callAppenders synchronization causes java.lang.Thread.State: BLOCKEDMove org.apache.log4j.Category to reentrant read/write locks .

甚至AsyncAppender不是没有过多的锁: AsyncAppender.doAppend() does not need to be synchronizedDeadlock in 1.2.15 caused by AsyncAppender and ThrowableInformation classes .还要注意 AsyncAppender overflow .

一个警告是始终将根类别级别限制为至少 INFO 或更高级别。这将防止记录调用获取上述问题中提到的不必要的锁。仅限制 appender 阈值是不够的,因为稍后会考虑到。参见 explanation with publish/subscribe analogy :

To answer your question about how threshold interacts with category, basically think of it is as a publish/subscribe. The category sets what is published by the logger, the threshold sets the subscription level of the appender.

如果需要,可以单独为感兴趣的嵌套类别赋予较低的优先级。

关于java - log4j 的生产设置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3537870/

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