Search code examples
javajersey-2.0dropwizardjersey-client

How to disable logging in Jersey Client 2.x?


I run a simple Dropwizard (1.2.0) web service in a test using a Jersey client (2.25.1) to invoke the service endpoint. For every request I get a log entry on the console, e.g:

127.0.0.1 - - [25/Oct/2017:21:17:10 +0000] "GET /query?name=John+Doe+1 HTTP/1.1" 200 48 "-" "Jersey/2.25.1 (HttpUrlConnection 1.8.0_92)" 84
127.0.0.1 - - [25/Oct/2017:21:17:10 +0000] "GET /query?name=John+Doe+2 HTTP/1.1" 200 48 "-" "Jersey/2.25.1 (HttpUrlConnection 1.8.0_92)" 84
127.0.0.1 - - [25/Oct/2017:21:17:10 +0000] "GET /query?name=John+Doe+0 HTTP/1.1" 200 48 "-" "Jersey/2.25.1 (HttpUrlConnection 1.8.0_92)" 84

I would like to disable these log entries to be printed on the console, since they are cluttering my output. I am assuming they are originating from the Jersey client? Am I wrong? So I tried to disable it, when creating my client, as such:

ClientConfig clientConfig = new ClientConfig();
clientConfig.property(LOGGING_FEATURE_LOGGER_LEVEL_CLIENT, Level.OFF);
Client client = ClientBuilder.newClient(clientConfig);
return client;

But this gives no effect - the log entries are still dumped on the console.

How do I disable these log entries?


Solution

  • They are request logs printed by dropwizard server. If you just don't want them to be printed on console you can log them to a file. Add below config below server: property in your test yaml config file.

    requestLog:
        timeZone: UTC
        appenders:
          - type: file
            currentLogFilename: /var/log/request.log
            threshold: ALL
    

    You may also disable it by specifying no appenders as below in your test config.

    requestLog:
       appenders: []