tags:

views:

113

answers:

4

Here is my current log4j settings file. 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. I checked my open file descriptors I was only using 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)

"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)
A: 

This looks normal. I don't see how this alone could cause log4j blocking. Maybe you could post a thread dump of your issue?

Gary
+1  A: 

%F:%L has serious performance impact. Although I don't see how they'd cause locking, I'd consider omitting them for production.

Yoni
Agreed. Instead, compile your code with debug information and you will get the line numbers in stack traces when errors occur.
AngerClown
+1  A: 

Are you creating a Logger for each class using the standard private static final Logger logger = Logger.getLogger(Foo.class); where Foo is the class in which the logger is declared? If you only have 1 Logger instance in your entire application, there could be some contention if there is a lot of logging.

AngerClown
A: 

This guy apparently had a similar problem (link).
It is puzzling though why your app is hanging. Are they all blocked at log4j classes? I see at least the one you posted was writing an "ERROR" log. Could that be the cause?

Maybe you want to post the full dump?

Enno Shioji