This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am trying to use Log4J logging in a web application, deployed on BEA.
I am writing this down from memory since I can not access my code right now. My apologies.
First, in a Java class (e.g. mypackage.MyClass), I put code like:
Second, I have created a log4j.properties file and I have put it in the web project's WEB-INF/classes folder (later on, I tried putting it in other classpath locations as well).
The properties file basically just defines the root logger, and configures it to a console output appender, at INFO level. I copied the property file content directly from an example, so I assume nothing is wrong with it (later on I tried to create a specific logger for "mypackage" as well).
When starting up the server and application, and passing through the code of MyClass, the following appears in the console output:
log4j:WARN No appenders could be found for logger (mypackage.MyClass)
log4j:WARN Please initialize the log4j system properly.
What do I need to do to get it working? It is a web application, so I assume I do not need to call some initialization method in advance, like I noticed in stand-alone Java application examples.
No change since my last post. The development team agreed in creating a Servlet called InitServlet that is loaded on startup, initializing the code in its 'init(ServletConfig)' method. Here's the method:
And the web.xml snipplet:
Joined: Jul 19, 2009
Thanks Kjeld for sharing the solution.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com