简体   繁体   English

log4j的生产设置文件?

[英]Production settings file for log4j?

Here is my current log4j settings file. 这是我当前的log4j设置文件。 Are these settings ideal for production use or is there something I should remove/tweak or change? 这些设置是否适合生产使用,还是应该删除/调整或更改? I ask because I was getting all my threads being hung due to log4j blocking. 我问,因为我的所有线程都因为log4j阻塞而被挂起。 I checked my open file descriptors I was only using 113. 我检查了我的打开文件描述符,我只使用了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

UPDATE*** Adding thread dump sample from all my threads (100) 更新***从我的所有线程添加线程转储样本(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 is vulnerable to deadlocks when toString() produces nested logging. toString()生成嵌套日志记录时,Log4j 1.2很容易出现死锁

See old aged still unresolved issues like Log4J can create deadlock conditions (concurrent package donation) and Deadlock with RollingFileAppender . 查看旧的仍然未解决的问题,例如Log4J可以创建死锁条件(并 发包 捐赠)使用RollingFileAppender的死锁

It also has performance-killing lock synchronization issues under heavy concurrent load. 它还具有在严重并发负载下的性能消除锁同步问题。 Like Category callAppenders synchronization causes java.lang.Thread.State: BLOCKED and Move org.apache.log4j.Category to reentrant read/write locks . 类别callAppenders同步导致java.lang.Thread.State:BLOCKED并将org.apache.log4j.Category移动到可重入读/写锁

Even AsyncAppender is not free of excessive locks: AsyncAppender.doAppend() does not need to be synchronized and Deadlock in 1.2.15 caused by AsyncAppender and ThrowableInformation classes . 即使AsyncAppender也没有过多的锁定: AsyncAppender.doAppend()不需要同步,并且在1.2.15中由AsyncAppender和ThrowableInformation类引起的死锁 Also beware of AsyncAppender overflow . 还要注意AsyncAppender溢出

One caveat is to always constrain root category level to at least INFO or higher. 需要注意的是始终将根类别级别限制为至少INFO或更高。 This would prevent logging calls from acquiring unnecessary locks mentioned in the above issues. 这样可以防止日志记录调用获取上述问题中提到的不必要的锁。 Just limiting appender threshold is not sufficient as it is taken into account later. 仅仅限制appender阈值是不够的,因为稍后会考虑它。 See 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. 类别设置记录器发布的内容,阈值设置appender的订阅级别。

Nested categories of interest can be individually given lower priorities if needed. 如果需要,嵌套的兴趣类别可以单独给予较低的优先级。

Are you creating a Logger for each class using the standard private static final Logger logger = Logger.getLogger(Foo.class); 您是否使用标准的private static final Logger logger = Logger.getLogger(Foo.class);为每个类创建一个Logger private static final Logger logger = Logger.getLogger(Foo.class); where Foo is the class in which the logger is declared? 其中Foo是声明记录器的类? If you only have 1 Logger instance in your entire application, there could be some contention if there is a lot of logging. 如果整个应用程序中只有1个Logger实例,那么如果有大量日志记录可能存在争用。

%F:%L has serious performance impact. %F:%L具有严重的性能影响。 Although I don't see how they'd cause locking, I'd consider omitting them for production. 虽然我不知道它们是如何导致锁定的,但我会考虑省略它们用于生产。

This looks normal. 这看起来很正常。 I don't see how this alone could cause log4j blocking. 我不明白这是如何导致log4j阻塞的。 Maybe you could post a thread dump of your issue? 也许您可以发布您的问题的线程转储?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM