Skip to content

Instantly share code, notes, and snippets.

@isopropylcyanide
Last active September 5, 2020 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isopropylcyanide/5dcdf95e5e4fc40951ce43fa33c1543c to your computer and use it in GitHub Desktop.
Save isopropylcyanide/5dcdf95e5e4fc40951ce43fa33c1543c to your computer and use it in GitHub Desktop.
/**
* This logging filter helps exclude logging requests and responses for URIs that match a set of excluded URIs
*/
public class WhitelistedServerLoggingFilter implements ContainerRequestFilter, ContainerResponseFilter, WriterInterceptor {
private final RequestResponseBuilder requestResponseBuilder;
private final Logger logger;
/**
* A get of paths for which the server request and response logging will not be performed
* if the URI matches any of the path specified in this get
*/
private final Set<String> excludedPaths;
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
String path = requestContext.getUriInfo().getPath();
if (excludedPaths.stream().noneMatch(path::contains)) {
//this uri is not in the exclude set..Good to log
StringBuilder requestLog = requestResponseBuilder.buildRequestLog(requestContext);
log(requestLog);
}
}
....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment