Cause of Problem: I'm trying to use Log4j in conjunction with apache commons logging to write to log files. I've placed a commons-logging.properties in the WEB-INF\classes folder. The application uses log4j and writes to log files when running in Websphere 6.1. When the application runs in the application server, it uses the default 'org.apache.commons.logging.impl.Jdk14Logger' other than
'org.apache.commons.logging.impl.Log4jLogger'.
commons-logging.properties:
priority=1
org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl
log4.properties:
log4j.rootCategory=DEBUG, CONSOLE, LOGFILE
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=INFO
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=/cust/logs/SLKServices/axis.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.Threshold=DEBUG
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x %L- %m%n
Solution:
Because websphere uses the default 'org.apache.commons.logging.impl.Jdk14Logger', therefore we need to make the websphere to load the configured log4j of our project other than load its’ default configure, we only need to add the following configure file to the foler “META-INF/services” of the ear package.
File Name : org.apache.commons.logging.LogFactory :
Just make the contents of that file as the following:
org.apache.commons.logging.impl.Log4jFactory
The META-INF/services approach has been working for us (who give the help in the forum) for years on many different versions of WAS. (We're on 6.1 now) You don't need (or likely want) to change the classloader ordering policy like the following.
commons-logging.properties:
priority=1
org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl
A couple references:
http://www-1.ibm.com/support/docview.wss?uid=swg27010153