You can't have log4j route exception errors to the log file if you don't catch the exception and pass it to log4j... If you allow the exception to propagate all the way up, it will be logged by the container. Short story: if you want to control where something gets logged to, you need to control how it is logged.

L.

Kelly.Graus wrote:
Hello,

I am writing an application using Struts (2.0.11), Spring (2.5.1), and
Hibernate (3.2.6), running on Tomcat (6.0.13).  We have a legacy webapp
running on Tomcat that outputs some important information to the default
Tomcat logs.  We aren't really in a position to change that application, so
we're trying to update our new webapp to put all messages in a different log
file.  I'm trying to do this using log4j (1.2.15).

So far, I can add messages to the new log in my java code.  I am also
getting freemarker.cache debug messages in the new log.  However, all other
messages are still being put in the default Tomcat logs.  For example, if
the database I'm trying to access closes its connection and I don't catch
the exception that is thrown, it gets printed to the screen, and put in the
catalina log.  I would like that exception to go in the new log file instead
(and yes, eventually I will catch the exception and have struts display a
nicer error message for the user).

Below are the relevant parts of my web.xml, and my log4j.properties file. Any help would be greatly appreciated!

Thanks!

Kelly


[web.xml]
[snip]
<context-param>
        <description>This context parameter specifies the name and location
        of the log4j properties file.</description>
        <param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value> </context-param>
<filter>
    <filter-name>struts2-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
  </filter>
  <filter>
    <filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
  </filter>
  <filter>
    <filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>
<filter-mapping>
    <filter-name>struts2-cleanup</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
<listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>
[snip]

[log4j.properties]
log4j.rootLogger=DEBUG, rollingFileAppender

# Rolling file Appender
log4j.appender.rollingFileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.rollingFileAppender.File=${catalina.home}/logs/lessonDownloader.log
log4j.appender.rollingFileAppender.MaxFileSize=1024KB
log4j.appender.rollingFileAppender.MaxBackupIndex=10
log4j.appender.rollingFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.rollingFileAppender.layout.ConversionPattern=%d %p [%c] -
%m%n*

# Control logging for other packages
log4j.logger.org.apache.commons=WARN
log4j.logger.org.apache.struts2=WARN
log4j.logger.org.springframework=WARN
log4j.logger.org.hibernate=WARN
log4j.logger.org.apache.jasper=WARN
log4j.logger.org.apache.catalina=WARN
log4j.logger.com.opensymphony.xwork2=WARN



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to