Giter Site home page Giter Site logo

servlet-logging-filter's Introduction

Servlet logging filter

Java 8 Servlet filter for logging requests and responses

Web page equivalent is here

Usage

Filter implements javax.servlet.Filter from Servlet API 3.1.0 You can register the filter using web.xml descriptor.

<filter>
	<filter-name>LoggingFilter</filter-name>
	<filter-class>javax.servlet.filter.logging.LoggingFilter</filter-class>
</filter>
<filter-mapping>
	<filter-name>LoggingFilter</filter-name>
	<url-pattern>/*</url-pattern>
</filter-mapping>

or javax.servlet.ServletContext

public void onStartup(ServletContext servletContext) throws ServletException {
	Dynamic registration = servletContext.addFilter("LoggingFilter", new LoggingFilter());
	registration.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");
}

Init params

Name Default Description
loggerName class name Logger name for output
maxContentSize 1024 bytes Maximal logged body size in bytes
excludedPaths empty Comma sepparated list of URL prefixes e.g.: "/api,/admin"
requestPrefix REQUEST: First word on request output line
responsePrefix RESPONSE: First word on response output line

Customization

There are few methods for rewrite if you want:

Main filter processing

javax.servlet.filter.logging.LoggingFilter.doFilter

Creating description of request. Default is create JSON object.

javax.servlet.filter.logging.LoggingFilter.getRequestDescription

Creating description of response. Default is create JSON object.

javax.servlet.filter.logging.LoggingFilter.getResponseDescription

Output

REQUEST:{"sender": "127.0.0.1", "method": "GET", "path": "http://localhost:8080/test", "params": {"param1": "1000"}, "headers": {"Accept": "application/json", "Content-Type":"text/plain"}, "body": "Test request body"}
RESPONSE: {"status":200,"headers":{"Content-Type":"text/plain"},"body":"Test response body"}

servlet-logging-filter's People

Contributors

librucha avatar rosiecki avatar

Stargazers

 avatar

Watchers

James Cloos avatar Peng Yu avatar  avatar

Forkers

davidjirovec

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.