1

I have added this line

environment.jersey().register(new LoggingFeature(Logger
    .getLogger(LoggingFeature.class.getName()), Level.OFF, 
          LoggingFeature.Verbosity.PAYLOAD_TEXT, null));

in my run(Configuration configuration, Environment environment) method looking at this and this

I am only getting stuff in the logs if the Level is set to OFF and all my requests/response messages are logged as ERROR, but why ERROR?

Here is an example of the log:

ERROR  [11:17:41.603] [dw-31 - GET /helloworld] o.g.j.l.LoggingFeature -  1 

* Server has received a request on thread dw-31 - GET /helloworld
1 > GET http://localhost:8080/helloworld
1 > Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
1 > Accept-Encoding: gzip, deflate, sdch, br
1 > Accept-Language: en-US,en;q=0.8
1 > Cache-Control: max-age=0
1 > Connection: keep-alive
1 > Cookie: openid_provider=openid; _ga=GA1.1.1009619719.1483436711
1 > Host: localhost:8080
1 > Upgrade-Insecure-Requests: 1
1 > User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36

ERROR  [11:17:41.615] [dw-31 - GET /helloworld] o.g.j.l.LoggingFeature -  1 * Server responded with a response on thread dw-31 - GET /helloworld
1 < 200

My Resource class:

@Path("/helloworld")
@Produces(MediaType.APPLICATION_JSON)
public class HelloWorldResource {

    public HelloWorldResource() { }

    @GET
    public Response helloWorld(){
        System.out.println("Hello World");

        return Response.ok().build();

    }
}

My main application class:

public class ApiApplication extends Application<ApiConfiguration>{

public static void main(String[] args) throws Exception{
    new ApiApplication().run(args);
}

@Override
public void initialize(Bootstrap<ApiConfiguration> bootstrap) {
    // nothing to do yet
}

@Override
public void run(ApiConfiguration apiConfiguration, Environment environment) throws Exception {

    final TemplateHealthCheck healthCheck =
            new TemplateHealthCheck(apiConfiguration.getTemplate());
    environment.healthChecks().register("template", healthCheck);

    final HelloWorldResource helloWorldResource = new HelloWorldResource();
    final JerseyEnvironment jerseyEnvironment = environment.jersey();
    jerseyEnvironment.register(helloWorldResource);

    jerseyEnvironment.register(new LoggingFeature(Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), Level.OFF, LoggingFeature.Verbosity.PAYLOAD_ANY, Integer.MAX_VALUE));

    }
}
Community
  • 1
  • 1
Yantes
  • 251
  • 3
  • 18

1 Answers1

2

You shall try changing the LoggingFeature to -

environment.jersey().register(new LoggingFeature(
      Logger.getLogger(LoggingFeature.class.getName()), Level.FINE,
             LoggingFeature.Verbosity.PAYLOAD_TEXT, null));

Since the current logging is set to Level.OFF. The application does not try to log anything and returns from the filter implementation of ContainerRequestFilter and filter implementation of ContainerResponseFilter interfaces with the java.util.Logger within which the log(LogRecord) method is overriden by some subclass of Logger which is modifying the level to ERROR.

I would second the thought of this implementation to be considered as poor. Expecting at the same time that changing to Level.OFF shouldn't log anything at all. (at least not under ERROR)

At the same time the verbosity specified is LoggingFeature.Verbosity.PAYLOAD_TEXT so the entire

Content of HTTP headers as well as entity content of textual media types is logged.

which is the details after your [ERROR] message in the logs.

Naman
  • 27,789
  • 26
  • 218
  • 353
  • 1
    Thanks it helped, well I could'nt either get my head around it that logs were produced when set to `OFF` but nothing was produced when set to `ALL`. It did not occur to me to try out `FINE`. Just trying to figure out how to log when a specific request is called from a given user. But thanks a lot for the explanation @nullpointer – Yantes Mar 20 '17 at 08:03
  • @TheLearner I am not very sure where this belongs to at present. But this should be raised as unexpected behaviour(bug) to either of the libraries involved. – Naman Mar 20 '17 at 10:18
  • I will report it asap – Yantes Mar 20 '17 at 10:52