Last active
September 5, 2020 17:02
-
-
Save isopropylcyanide/5dcdf95e5e4fc40951ce43fa33c1543c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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