I have been developing a web service using WebSphere. I tried to add logging functionality using log4j. I used a servlet to initialize the log4j configuration using the suggestion in http://logging.apache.org/log4j/docs/manual.html. I also used the example log4j.xml files in http://www.laliluna.de/log4j-tutorial.html. I added the log4j jar file into the WEB-INF/lib directory and added the log4j.xml file into the WEB-INF/classes directory. However, I would lose my log4j.xml file whenever I rebuild my project. This because the entire WEB-INF/classes directory is rewritten when the project is rebuilt. So I moved the log4j.xml into the WEB-INF directory, along with other .xml files. However, when I run the project, I would get:
- R log4j:WARN No appenders could be found for logger (root).
- R log4j:WARN Please initialize the log4j system property.
I googled around a bit and found that the log4j.xml file needs to be in the classes directory. So I copied to log4j.xml file into the JavaSource directory. When the project is rebuilt, the file is automatically copied to the the WEB-INF/classes directory. When I ran the program again, it worked beautifully.
Some additional notes:
- log4j.dtd needs to be in the same directory as log4j.xml.
- When I test the web service using WebSpere v5.1 test environment, the log file is found in the root directory of my WebSphere Studio.