-1

I am trying to enable HTTP request/response logging in Jersey, running on Tomcat. My app is web.xml based and does not have an Application on ResourceConfig class.

This is what i have tried to enable LoggingFeature from my web.xml :

<init-param>
        <param-name>jersey.config.server.provider.classnames</param-name>
        <param-value>org.glassfish.jersey.logging.LoggingFeature</param-value>
    </init-param>

<init-param>
    <param-name>org.glassfish.jersey.logging.LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL</param-name>
    <param-value>java.util.logging.Level.FINEST</param-value>
</init-param>

<init-param>
    <param-name>org.glassfish.jersey.logging.LoggingFeature.LOGGING_FEATURE_LOGGER_NAME</param-name>
    <param-value>MyLoggerName</param-value>
</init-param>

but i don't see any Jersey logs in catalina.out or localhost_access.log

gaurav5430
  • 12,934
  • 6
  • 54
  • 111

1 Answers1

-1

This is how I made it work on Tomcat running from within Eclipse:

  1. Find out the path to tomcat running within Eclipse: Where can I view Tomcat log files in Eclipse?

  2. Create a logging.properties file there. In my case, the path was .../EclipseWorkSpace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/conf (You can copy this logging file from within your actual tomcat conf folder.)

  3. Within your application, create a logging.properties file in src/main/resources. (did not work when i directly created in WEB-INF/classes as mentioned in tomcat documentation :

Example logging.properties for the servlet-examples web application to be placed in WEB-INF/classes inside the web application: from https://tomcat.apache.org/tomcat-9.0-doc/logging.html )

  1. set your tomcat logging parameters in the above file, which overrides the default logging.properties file from /.metadata/.plugins/org.eclipse.wst.server.core/tmp0/conf from inside your app:

    handlers= java.util.logging.ConsoleHandler
    
    .level= FINE
    
    java.util.logging.ConsoleHandler.level = FINE
    java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
    

This will log 'FINE' level logs from Tomcat.

  1. Set logging properties in your jersey app:

    register(new LoggingFeature(Logger.getLogger(MyApplication.class.getName()), Level.INFO, LoggingFeature.Verbosity.PAYLOAD_TEXT, 2048));
    

OR

<init-param>
        <param-name>jersey.config.server.provider.classnames</param-name>
        <param-value>org.glassfish.jersey.logging.LoggingFeature</param-value>
    </init-param>

This will only log 'INFO' logs from jersey.

So, 4 and 5 effectively means that Tomcat would log all FINE logs, but Jersey would only log INFO logs, so in your log file (catalina.out) , you will only see INFO logs from Jersey, but FINE logs from everything else in Tomcat.

gaurav5430
  • 12,934
  • 6
  • 54
  • 111