Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

using log4j in Tomcat

 
YanJun Tong
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use log4j to trace any debig information in my application.However since it is my first time to use log4j I got some problem. Suppose my appication is in the path c:\tomcat\webapps\catania-web Since we all know I need a file to config my log4j.Let us say the file is called simplelog.properties.I put this file under the folder c:\tomcat\webapps\catania-web\WEB-INF. I put all my settings in the web.xml as follows:
<context-param>
<param-name>LogConfig</param-name>
<param-value>cataniaLog.properties</param-value>
</context-param>
So I can trigger this parameter by getServletContext().
The problem is that I do not know how to set the <param-value> tag so that my application can find my properties file. My current approach is to use the absolute path i.e. <param-value>c:/tomcat/webapps/catania-web/WEB-INF/cataniaLog.properties</param-value>. But I know it is not a good idea to put absolute path here. Could anybody tell me how to write a abstract path and where should I put my simplelog.properties thanks in advance
 
Eelco den Heijer
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can put the log4j.properties for server level (used by the container) in $CATALINA_HOME/common/classes (or anywhere on the classpath of tomcat); this will regulate all debug messages coming from the classloader of tomcat itself.

For each web application you can put the log4j.properties in the WEB-INF/classes directory. You can explicitly instantiate properties file like you say, but it is not necessary.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!