Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
171 lines (127 sloc) 4.97 KB


© 2016-2019 Resurface Labs Inc.

Logging usage of Java cloud apps, with user privacy by design.



Requires Java 8+ and Java servlet classes, which are not included. No other dependencies to conflict with your app.

Installing with Maven

Add this section to pom.xml:


Add this section too if servlet classes are not already available.


Logging From Servlet Filter

After installing the library, add a logging filter to web.xml.

        <param-value>include strict</param-value>

Add a CDATA section when specifying multiple rules at once like this:

            include strict
            sample 10

Logging From Spring Boot

After installing the library, configure a FilterRegistrationBean to add a logging servlet filter.

public FilterRegistrationBean httpLoggerFilter() {
    FilterRegistrationBean frb = new FilterRegistrationBean();
    frb.setFilter(new io.resurface.HttpLoggerForServlets());
    frb.addInitParameter("url", "https://...");
    frb.addInitParameter("rules", "include strict");
    return frb;

Logging From Spark Framework

After installing the library, create a logger and call it from the routes of interest.

import io.resurface.HttpLogger;

HttpLogger logger = new HttpLogger("https://...", "include strict");

get("/hello", (request, response) -> {
    String response_body = "Hello World";
    logger.log(request.raw(), response.raw(), response_body);
    return response_body;

post("/hello_post", (request, response) -> {
    String response_body = "POSTED: " + request.body();
    logger.log(request.raw(), response.raw(), response_body, request.body());
    return response_body;

Alternatively configure an after filter to log across multiple routes at once.

after((request, response) -> {
    if (response.body() != null) {  // log successful responses only, not 404/500s
        logger.log(request.raw(), response.raw(), response.body(), request.body());

Logging From Jersey

After installing the library, register a logger as a Jersey filter/interceptor. Note this will only log usage when a response body is returned.

ResourceConfig resourceConfig = new ResourceConfig(...);
resourceConfig.register(new io.resurface.HttpLoggerForJersey("https://...", "include strict"));
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, resourceConfig, false);

Logging With API

Loggers can be directly integrated into your application using our API. This requires the most effort compared with the options described above, but also offers the greatest flexibility and control.

API documentation

Protecting User Privacy

Loggers always have an active set of rules that control what data is logged and how sensitive data is masked. All of the examples above apply a predefined set of rules (include strict), but logging rules are easily customized to meet the needs of any application.

Logging rules documentation

You can’t perform that action at this time.