In web.xml...

    <listener>
        <listener-class>
        org.apache.log4j.servlet.ServletContextLogAppenderListener
        </listener-class>
    </listener>

in log4j.xml...

    <appender name="ServletContext" class="org.apache.log4j.servlet.ServletContextLogAppender">
        <param name="servletContextPath" value="/mycontext"/>
        <param name="Threshold" value="debug"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="[%-5p][%-8.8t]: %39.39c %x- %m"/>
        </layout>
    </appender>

Notice the conversion pattern ends with "%m" instead of "%m%n".  This is because when the message goes through the servlet context logging mechanism, the latter adds the newline, so adding it to the conversion pattern above would result in 2 newlines, which is why we leave it out.

Jake

On Tue, 11 May 2010 18:21:40 +0200
 Thorbjoern Ravn Andersen <r...@runjva.com> wrote:
Den 11/05/10 18.00, Jacob Kjome skrev:
It's possible via Log4j.  See...
http://svn.apache.org/repos/asf/logging/sandbox/log4j/log4j_sandbox/tags/LOG4J_SANDBOX_ALPHA3/src/java/org/apache/log4j/servlet/

specifically...

ServletContextLogAppender.java
ServletContextLogAppenderListener.java

Interesting, with an interesting approach. I could not immediately see from the source where ServletContextLogAppender.setServletContextPath(...) is set, as it appears to be quite important for this mechanism to work. Is it to be set in log4j.xml, or did I miss something?

--
  Thorbjørn Ravn Andersen  "...plus... Tubular Bells!"

_______________________________________________
slf4j-user mailing list
slf4j-user@qos.ch
http://qos.ch/mailman/listinfo/slf4j-user


_______________________________________________
slf4j-user mailing list
slf4j-user@qos.ch
http://qos.ch/mailman/listinfo/slf4j-user

Reply via email to