Filter

LogWEx can be installed as a servlet filter in a Web Application.

  • add the archive logwex-core-1.x.x.jar into the WEB-INF/lib/ directory of your war archive
  • add this in WEB-INF/web.xml :
    <filter>
        <filter-name>logwex</filter-name>
        <filter-class>org.sewatech.logwex.MDCPreparerFilter</filter-class>
    </filter>
    
    <filter-mapping>
        <filter-name>logwex</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
  • configure your Log4J PatternLayout

Valve

TODO (version 1.1)

Log4J PatternLayout

LogWEx put the request data into Log4J's MDC. You can print those data into your log file (or console) by adding some %X... conversions to the PatternLayout. For example, in a log4j.xml file :

<log4j:configuration>
    <appender name="FILE" class="org.apache.log4j.FileAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="conversionPattern" value="%d %p %X{request.userName} - %m%n"/>
        </layout>
    </appender>
    ...
</log4j:configuration>

Here are some of the properties that are available in the MDC :

  • request.userName
  • session.id
  • request properties : request.scheme, request.serverName, request.serverPort, request.contextPath, request.servletPath, request.protocol, request.method, request.secure,...