MENU

Parsing HTTP with Java Log Filter

TOC

Analyze HTTP requests with Java log filter

javax.servlet.Filterto implement a convenient way to parse the contents of HTTP requests and output logs.FilterClasses.

This log filter uses "java.util.logging.Logger" for log output, and the information output can be changed by changing the log level.

What is javax.servlet.Filter?

When building a web application, in addition to the main business processing, it is necessary to perform common secondary processing before and after the main business processing.
For example, client authentication, authority checking, logging, etc.
Coding such side processing in each resource becomes a major cause of hindering software maintainability, resulting in an application that is difficult to maintain.

If you implement javax.servlet.Filter, you can have this secondary process commonly performed before the request is passed to the servlet class.
Filters can be configured in web.xml, giving you the flexibility to add or remove filters without changing the source code.


Try using log filters

Let's actually use the log filter to analyze HTTP requests by passing filters through HTTP requests.
In this issue.TomcatThe examples application is available from the beginning in the
This filter can be run immediately with the following settings

1.source codeand compile.
2. Place the compiled class files under "/examples/WEB-INF/classes".
3. Set the following definitions in web.xml.
  LogFilter
   LogFilter
   
    logging.Level
    FINE
   
  
  
   LogFilter
   /*

The url-pattern when using the Struts framework is as follows.

   *.do

Check the log output results of running the Sessions Example screen.
Web application analysis with javax.servlet.Filter log filter

Output log information and log level

Log output contents

log information log level
Cookie Information fine
HTTP Header Information fine
HTTP and other information fine
HTTP Request Parameters CONFIG
Objects in the request scope CONFIG
Session Scope Objects CONFIG
Memory usage before and after request CONFIG
Screen transition information INFO

Log levels should be used as follows

  • FINE: Outputs the most detailed logs; set this if you want to analyze HTTP requests in detail.
  • CONFIG ... Outputs a somewhat detailed log. It is recommended to keep this level during the development period.
  • INFO・・・・ outputs screen transition information only.

How to change the log level
The logging output level can be changed by setting the initialization parameter logging.Level.
Example:

   logging.Level
    INFO

source code

TOC