How to Collect Servlet Web Request Details
  • 1 Minute to read
  • Dark
    Light
  • PDF

How to Collect Servlet Web Request Details

  • Dark
    Light
  • PDF

Article Summary

To add additional logging from Servlet Filters follow the instructions in this document, to get the stackify-log-servlet project go to our GitHub Page.

By using a Java Servlet Filter for your Java Apps, you will be able to capture web request details along with your log messages.

Stackify supports adding filters to J2EE and JAX-RS servlets.

stackify-log-servlet needs to be used in conjunction with one of our java logging libraries.

The web request details will be attached to exceptions that are sent to Retrace. Here are the details that we will capture:

  • User
  • User IP address
  • Server name
  • Request protocol
  • Request method (GET, POST, PUT, DELETE)
  • Request URL
  • Referral URL
  • HTTP headers
  • HTTP cookies (names only)
  • HTTP session attributes (names only)
  • Query string parameters

We do not currently capture any details from the POST/PUT body.

In addition to the web request details, we will also generate a transaction id in the filter. This transaction id will be added to all messages that are logged from that request thread. This gives you an easy way to identify all messages that were logged from the same request.

Installation

Add it as a maven dependency:

<dependency>
    <groupId>com.stackify</groupId>
    <artifactId>stackify-log-servlet<artifactId>
    <version>INSERT_LATEST_MAVEN_CENTRAL_VERSION</version>
</dependency>

J2EE Servlet Usage

Add the StackifyLogFilter servlet filter and mapping to the web-app element in your web.xml file.

<web-app>
...
    <filter>
        <filter-name>StackifyLogFilter</filter-name>
        <filter-class>com.stackify.log.servlet.StackifyLogFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>StackifyLogFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
...
</web-app>

JAX-RS Servlet Usage

Add the StackifyLogFilter servlet filter to the servlet element in your web.xml file.

<servlet>
    ...
    <init-param>
        <param-name>jersey.config.server.provider.classnames</param-name>
        <param-value>com.stackify.log.servlet.jaxrs.StackifyLogFilter</param-value>
    </init-param>
    ...
</servlet>

Was this article helpful?