0

I am using Embedded Tomcat (Version 7.028). My Embedded Tomcat server is a configurable server which can add one or more web-apps to it.

I want to log the errors/info messages in Embedded Tomcat in one log file and maintain different log files for all the applications deployed on Embedded Tomcat. I have a log4j.properties file placed in the classpath for Embedded Tomcat. It is being read properly and I'm able to log the info and error messages for Tomcat. I have also declared all the loggers in my Embedded Tomcat as non-static.

I have put log4j.xml in the webapp's WEB-INF/classes location to override the log4j.properties of Embedded Tomcat (Referred to the Link). But the log4j.xml is not getting initiated. The log4j setup from Tomcat is only being used.

Please help me how to overcome this problem. Is there any configuration that can be added to the xml or the properties file?

Community
  • 1
  • 1
  • I figured out that only one classloader is being used for all the webapps in the embedded tomcat. Because there is only one class loader, the log4j initialized first by the embedded tomcat server is working, and the other webapps are not getting over-ridden. – haritejareddy Oct 04 '12 at 13:04
  • I have tried adding new WebappLoader like follows: `Context context = tomcat.addWebapp("/myApp", "/opt/test/myApp"); WebappLoader xcomLoader = new WebappLoader(context.getParentClassLoader()); addJarFileUrls(context, new File(jarFilesDirectory)); context.setLoader(myLoader); myLoader.start();` But this didnot work. On calling the start method I am getting errors. Am I doing something wrong? Please point me in the right direction. – haritejareddy Oct 09 '12 at 12:38

1 Answers1

0

Please try adding log4j jar in each web-application (I mean in WEB-INF/lib), I think that might solve your problem.

tonio
  • 484
  • 5
  • 15