Log4j does seem to work out of the box with Websphere 6 so I cobbled together some tips and advice from the web and wrote this mini guide. It was a couple of years but hopefully be useful to someone.
WebSphere uses commons-logging and so it’s in the root classloader. In addition, WebSphere 6.0 ships a commons-logging.properties with the following properties set:
org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger
Set application classloader mode as PARENT_LAST. This can be changed in eclispes EAR file deployment descriptor menu. This tells websphere to load the parent files last giving the application files priority. (the parent being the websphere root)
Also, create a new commons-logging.properties to the application classpath with the following entries:
priority=1
org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl
So basically the commons-logging.properties overrides the one packaged in websphere and returns it to the default logging system which is log4j.
NOTE: You also have to replace the commons-logging-api.jar that comes supplied with websphere, because IBM use the API and which doesn’t contain the log4j logger implementation.
Replace
With the commons-logging-api.jar downloaded from http://jakarta.apache.org/site/downloads/downloads_commons-logging.cgi
You should also import include it in your go to project properties, java build path and import external jar. Ensure it’s imported above the websphere runtime library otherwise it’ll read the other one first. You can change the order of the imports in project prop > java build path > order and export.
LOG4J Config
To configure log4j you’ll need to create a log4j.propertuies file or a log4j.xml file. This can be located in the application classpath (same level as the ‘com’ directory). Ideally this should be located outside of the EAR/WAR file, where it can be easily editing whilst the application is running without the need to redeploy.
Checklist:
- Created commons-logging.properties and log4j.properties in java classpath.
- Change application classloader mode as PARENT_LAST
- Import the commons-logging 1.1 jar file
- Ensure imported jar in imported before Websphere runtime
- Clean, Build and redeploy (also restart websphere)
More info:
http://wiki.apache.org/jakarta-commons/Logging/FrequentlyAskedQuestions
http://www.webagesolutions.com/knowledgebase/waskb/waskb004/index.html
http://www.mobilefish.com/developer/log4j/log4j_quickguide_examples.html


