Log Filter Utils

A set of helpful utilities for the conventional log filters

License

License

Categories

Categories

IDE Development Tools Jersey Program Interface REST Frameworks
GroupId

GroupId

com.github.isopropylcyanide
ArtifactId

ArtifactId

jersey-log-utils
Last Version

Last Version

1.3
Release Date

Release Date

Type

Type

jar
Description

Description

Log Filter Utils
A set of helpful utilities for the conventional log filters
Project URL

Project URL

https://github.com/isopropylcyanide/jersey-log-utils
Source Code Management

Source Code Management

https://github.com/isopropylcyanide/jersey-log-utils

Download jersey-log-utils

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.isopropylcyanide/jersey-log-utils/ -->
<dependency>
    <groupId>com.github.isopropylcyanide</groupId>
    <artifactId>jersey-log-utils</artifactId>
    <version>1.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.isopropylcyanide/jersey-log-utils/
implementation 'com.github.isopropylcyanide:jersey-log-utils:1.3'
// https://jarcasting.com/artifacts/com.github.isopropylcyanide/jersey-log-utils/
implementation ("com.github.isopropylcyanide:jersey-log-utils:1.3")
'com.github.isopropylcyanide:jersey-log-utils:jar:1.3'
<dependency org="com.github.isopropylcyanide" name="jersey-log-utils" rev="1.3">
  <artifact name="jersey-log-utils" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.isopropylcyanide', module='jersey-log-utils', version='1.3')
)
libraryDependencies += "com.github.isopropylcyanide" % "jersey-log-utils" % "1.3"
[com.github.isopropylcyanide/jersey-log-utils "1.3"]

Dependencies

compile (2)

Group / Artifact Type Version
org.glassfish.jersey.core : jersey-server jar 2.25.1
org.slf4j : slf4j-api jar 1.7.25

test (2)

Group / Artifact Type Version
org.mockito : mockito-core jar 3.0.0
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Jersey Log Utils

Maven Central Travis (.org) Codecov GitHub

A set of useful utilities for the Jersey Server and Client log filters. These are

Maven Artifacts

This project is available on Maven Central. To add it to your project you can add the following dependency to your pom.xml:

    <dependency>
        <groupId>com.github.isopropylcyanide</groupId>
        <artifactId>jersey-log-utils/artifactId>
        <version>1.0</version>
     </dependency>

Features

Filter Use Case
WhitelistedServerLoggingFilter Exclude server requests and responses log for certain URI, say healthchecks
WhitelistedClientLoggingFilter Exclude client requests and responses log for certain URI, say heavy GET calls
DelayedServerRequestResponseLoggingFilter Delay server requests and response log for specific response codes

Usage

  • Register the filter to your Jersey Environment
     excludeContexts = Sets.newHashSet(
                new ExcludeContext("v1/get"), //all Http Verbs
                new ExcludeContext(HttpMethod.PUT, "v1/update") //PUT only
        );
    environment.jersey().register(
      new WhiteListedServerLoggingFeature(excludeContexts, maxEntitySize)
    );
    environment.jersey().register(
      new DelayedServerRequestResponseLoggingFilter(logger, responseCondition: ResponseCondition.ON_RESPONSE_4XX_5XX)
    );
    excludeContexts = Sets.newHashSet(
            new ExcludeContext(HttpMethod.GET, "v1/get"),
            new ExcludeContext("v1/update") //all Verbs
    );
    new JerseyClientBuilder(environment).register(
            new WhitelistedClientLoggingFilter(excludeContexts, logger, maxEntitySize)
    );

Why

The standard LoggingFilter which has been deprecated as of Jersey 2.26 is a universal logging filter and does a great job of logging requests and responses at the server.

However, it does so blindly, as it encounters each phase during the request lifecycle, and does it for every request. There may be production use cases that would require modification of this standard Logging Filter

  • We would not want to log all requests and responses, only the ones that match a particular criteria. Example of this would be requests that are from an ELB or health check system or static assets. Request entry need to be logged but not the payloads

  • For servers operating at high QPS, all successful requests and responses are logged which quickly leads to log rotation. The other alternative is to not register the filter at all which is not what we want. We only want to log where the responses are 4xx or 409 or 400 and 500 or simply 200 requests. Such feature is not supported in the default filter as by the time response is received, the request is already logged.

  • For client network calls, we might not want to log everything. Only what is required.

Support

Please file bug reports and feature requests in GitHub issues.

License

Copyright (c) 2012-2020 Aman Garg

This library is licensed under the Apache License, Version 2.0.

See http://www.apache.org/licenses/LICENSE-2.0.html or the LICENSE file in this repository for the full license text.

Versions

Version
1.3
1.2
1.1
1.0