Hi Gregor, I am not sure about the definite solution, but as you got no other answers, try this:
Drop an additional log4j.jar in the webapps lib folder. Only this, IMHO, makes the webapp load another instance of log4j so it can be configured independently. The log4j.xml would then be searched for in WEB-INF/classes as well. Any other experiences with multiple log4j instances in Tomcat AND the webapps? Georg Gregor Schneider wrote:
Hi guys, I've setup Tomcat on my Debian Box so that all loging goes to $CATALINA_HOME/logs/tomcat.log I've placed the files log4j.(xml,dtd) int $CATALINA_HOME/common/classes, and it runs like charm. Now, I've added another logger which is supposed to log the output of our apps only. That logger should be in place as a default logger for all web-apps. The benefit is, that no web-app has to provide it's own log4j.xml. This is a snipped of the log4j.xml from $CATALINA_HOME/common/classes where - the root-logger logs everything coming from Tomcat Engine - CompassLogger logs everything coming from our applications: <!-- Tomcat Daily Rolling File Appender TRACE, DEBUG, INFO --> <appender name="TomcatDailyFileAppenderInfo" class="org.apache.log4j.DailyRollingFileAppender"> <param name="datePattern" value="'.'yyyy-MM-dd" /> <param name="Append" value="true" /> <param name="file" value="${catalina.home}/logs/tomcat.log.INFO" /> ... </appender> <!-- Tomcat Daily Rolling File Appender WARNING --> <appender name="TomcatDailyFileAppenderWarning" class="org.apache.log4j.DailyRollingFileAppender"> <param name="datePattern" value="'.'yyyy-MM-dd" /> <param name="Append" value="true" /> <param name="file" value="${catalina.home}/logs/tomcat.log.WARN" /> ... </appender> <!-- Tomcat Daily Rolling File Appender ERROR --> <appender name="TomcatDailyFileAppenderError" class="org.apache.log4j.DailyRollingFileAppender"> <param name="datePattern" value="'.'yyyy-MM-dd" /> <param name="Append" value="true" /> <param name="file" value="${catalina.home}/logs/tomcat.log.ERROR" /> ... </appender> <!-- COMPASS Tomcat Daily Rolling File Appender TRACE, DEBUG, INFO --> <appender name="CompassDailyFileAppenderInfo" class="org.apache.log4j.DailyRollingFileAppender"> <param name="datePattern" value="'.'yyyy-MM-dd" /> <param name="Append" value="true" /> <param name="file" value="${catalina.home}/logs/compass.log.INFO" /> ... </appender> <!-- COMPASS Tomcat Daily Rolling File Appender WARNING --> <appender name="CompassDailyFileAppenderWarning" class="org.apache.log4j.DailyRollingFileAppender"> <param name="datePattern" value="'.'yyyy-MM-dd" /> <param name="Append" value="true" /> <param name="file" value="${catalina.home}/logs/compass.log.WARN" /> ... </appender> <!-- COMPASS Tomcat Daily Rolling File Appender ERROR --> <appender name="CompassDailyFileAppenderError" class="org.apache.log4j.DailyRollingFileAppender"> <param name="datePattern" value="'.'yyyy-MM-dd" /> <param name="Append" value="true" /> <param name="file" value="${catalina.home}/logs/compass.log.ERROR" /> ... </appender> <root> <priority value="INFO" /> <appender-ref ref="TomcatDailyFileAppenderInfo" /> <appender-ref ref="TomcatDailyFileAppenderWarning" /> <appender-ref ref="TomcatDailyFileAppenderError" /> </root> <logger name="CompassLogger" additivity="false"> <level value="WARNING" /> <appender-ref ref="CompassDailyFileAppenderInfo" /> <appender-ref ref="CompassDailyFileAppenderWarning" /> <appender-ref ref="CompassDailyFileAppenderError" /> </logger> ... </log4j:configuration> Well, this runs like charm. However, now I'm gaving another web-app which is supposed to have it's own log-file and should not use CompassLogger but create it's own logger. I've created the following file log4j.xml 8again a snippet since it's quite some code) and put it into $CATALINA_HOME/webapps/MyWebApp/WEB-INF/classes (together with log4j.dtd): <!-- SSO Daily Rolling File Appender TRACE, DEBUG, INFO --> <appender name="SSODailyFileAppenderInfo" class="org.apache.log4j.DailyRollingFileAppender"> <param name="datePattern" value="'.'yyyy-MM-dd" /> <param name="Append" value="true" /> <param name="file" value="${catalina.home}/logs/sso.log.INFO" /> ... </appender> <!-- SSO Daily Rolling File Appender WARNING --> <appender name="SSODailyFileAppenderWarning" class="org.apache.log4j.DailyRollingFileAppender"> <param name="datePattern" value="'.'yyyy-MM-dd" /> <param name="Append" value="true" /> <param name="file" value="${catalina.home}/logs/sso.log.WARN" /> ... </appender> <!-- SSO Daily Rolling File Appender ERROR --> <appender name="SSODailyFileAppenderError" class="org.apache.log4j.DailyRollingFileAppender"> <param name="datePattern" value="'.'yyyy-MM-dd" /> <param name="Append" value="true" /> <param name="file" value="${catalina.home}/logs/sso.log.ERROR" /> ... </appender> <logger name="SSOLogger" additivity="false"> <level value="INFO" /> <appender-ref ref="SSODailyFileAppenderInfo" /> <appender-ref ref="SSODailyFileAppenderWarning" /> <appender-ref ref="SSODailyFileAppenderError" /> </logger> Within my Servlet, I'm having the following peace of code to initialize the logger: public void init(ServletConfig aConfig) throws ServletException { super.init(aConfig); DOMConfigurator.configure("log4j.xml"); ssoLogger = Logger.getLogger("SSOLogger"); However, when the servlet is started, I'm getting the following Exception in catalina.out *sic*: log4j:ERROR Could not parse file [log4j.xml]. java.io.FileNotFoundException: /home/tomcat/packages/apache-tomcat-5.5.20/logs/log4j.xml (No such file or directory) I've read the log4j-docs, read all the Tomcat-docs about Tomcat & log4j (which are not too helpful, I'm afraid), browsed through the "complete log4j-manual - the one you'll have to buy), but nothing could answer my questions: 1. Is it possible create a default logger with a log4j.xml-configuration in $CATALINA_HOME/common/classes PLUS create some application-specific loggers with a log4j.xml-configuration in $CATALINA_HOME/webapps/MyWebApp/WEB-INF/classes? 2. If so, is it correct that I have need to define the root-logger only in my default-logger-config (common/classes)? 3. Why is everybody writing that I have to drop my log4j.xml into $CATALINA_HOME/webapps/MyWebApp/WEB-INF-classes, however, log4j is searching for a file $CATALINA_HOME/ogs/log4j.xml ? I know it's quite some log4j-stuff, and this is a Tomcat-mailinglist, however, I guess this is a real-life-example referring to Tomcat AND log4j, so hopefully somebody here can shed some light. Any suggestions welcome! Gregor
--------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]