Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-521

Servlet filter which puts servlet-specific data into MDC

    XMLWordPrintable

Details

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 0.9.18
    • logback-classic
    • None

    Description

      Attached you can find a servlet filter which implements a strategy to put servlet-specific data into the SL4F MDC using the following keys:

      • slf4j.servlet.requestId - Unique ID of the single HTTP request handled by this filter
      • slf4j.servlet.sessionId - ID of the HTTP session this HTTP request is associated with or "" if no HTTP session was created yet
      • slf4j.servlet.contextPath - Web apps context path
      • slf4j.servlet.userName - Name of authenticated user or "" if no user is authenticated

      This data is removed after the request is processed.

      The following configuration parameters are supported by this filter:

      • maxSessionIdLength - limiting the HTTP session id length to a certain value, e.g. for WebLogic this could be 52 (default: -1 [unlimited])

      To use this filter add the following lines to the web.xml file:

      <code>
      <filter>
      <filter-name>RequestLogFilter</filter-name>
      <filter-class>ch.qos.logback.classic.RequestLogFilter</filter-class>
      <init-param>
      <param-name>maxSessionIdLength</param-name>
      <param-value>52</param-value>
      </init-param>
      </filter><br>
      :
      <filter-mapping>
      <filter-name>RequestLogFilter</filter-name>
      <url-pattern>/*</url-pattern>
      </filter-mapping>
      <code>

      An SLF4 Logger named ch.qos.logback.classic.RequestLogFilter is used to log the start end end of calling the filter chain. This information should go into a separate log file.

      Attachments

        1. logback-test.xml
          1.0 kB
          Torsten Juergeleit
        2. MoreMdcServletFilter.java
          2 kB
          Hendy Irawan
        3. RequestLogFilter.java
          8 kB
          Torsten Juergeleit
        4. RequestLogFilterTest.java
          2 kB
          Torsten Juergeleit

        Activity

          People

            ceki Ceki Gülcü
            tjuerge Torsten Juergeleit
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: