I've got an application I've developed in Dropwizard (0.9), and part of our internal infrastructure routinely pings the admin healthcheck REST endpoint to validate that the service is up. This adds a great deal of:
127.0.0.1 - - [26/Sep/2016:21:47:04 +0000] "GET /healthcheck HTTP/1.1" 200 - "-" "curl/7.43.0" 27
to the logfiles. Adjusting our internal tools is out of scope, so I'd like to configure the logger to silence these entries. Unfortunately, I can't identify the class generating these messages. Which class is responsible for the built-in /healthcheck endpoint, and will a simple:
logging:
loggers:
"com.class.that.is.responsible": ERROR
entry in the yaml config suppress them?
If you're using DropWizard v2.0.0 or later, you can use the built-in UriFilterFactory
. You can omit logs for specific endpoints by adding this to your dropwizard configuration .yaml:
server:
requestLog:
appenders:
- type: console
filterFactories:
- type: uri
uris:
- "/healthcheck"
Note: the DropWizard documentation uses type: URI
, which will not work. The @JsonTypeName
in the source code is uri
, so you have to use the lowercase name.
You can filter out the healthcheck requests with a logging filter.
That means there's a filter class:
@JsonTypeName("healthcheck-filter-factory")
public class HealthCheckLogFilter implements FilterFactory<IAccessEvent> {
@Override
public Filter<IAccessEvent> build() {
return new Filter<IAccessEvent>() {
@Override
public FilterReply decide(IAccessEvent event) {
if (event.getRequestURI().equals("/") || event.getRequestURI().equals("/healthcheck")) {
return FilterReply.DENY;
} else {
return FilterReply.NEUTRAL;
}
}
};
}
}
Then you register the filter class by writing its package name and class name into META-INF/services/io.dropwizard.logging.filter.FilterFactory
file:
com.my.package.path.goes.here.HealthCheckLogFilter
And finally you add it to the configuration .yaml file:
requestLog:
appenders:
- type: console
filterFactories:
- type: healthcheck-filter-factory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With