How to enable logging of requests headers + payload with Jersey 2.23 LoggingFeature

7,055 views
Skip to first unread message

t0tec

unread,
Jul 22, 2016, 11:51:35 AM7/22/16
to dropwizard-user
Since Jersey 2.23 LoggingFilter is deprecated, I'm trying to get it working with the new LoggingFeature of Jersey but can't figure it out.

    environment.jersey().register(new LoggingFeature(Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), LoggingFeature.Verbosity.PAYLOAD_ANY));
    environment.jersey().enable("LoggingFeature");

    System.out.println(environment.jersey().getResourceConfig().isEnabled(LoggingFeature.class));

Sources:


I'm using Dropwizard 1.0.0-rc5 + Jersey 2.23

x120

unread,
Jul 31, 2016, 3:48:38 PM7/31/16
to dropwizard-user
I've got same problem, have you figured it out?

Philip Warren

unread,
Jul 31, 2016, 5:46:13 PM7/31/16
to dropwizard-user
I'm able to get the LoggingFeature to work by adding it as you've shown. You shouldn't need to call `enable`, and the `isEnabled(LoggingFeature.class)` isn't expected to return true - here's the underlying code which is called: https://github.com/jersey/jersey/blob/3582ef0fab94352f2a9949cca9cb082bc750f07b/core-common/src/main/java/org/glassfish/jersey/model/internal/CommonConfig.java#L313-L316. You can see when registering the feature it is added to the `newFeatureRegistrations` in that class, which isn't checked by `isEnabled`.

One thing to double check might be that the logger for `org.glassfish.jersey.logging.LoggingFeature` is enabled at DEBUG level in your YAML config.

-- Philip

x120

unread,
Aug 1, 2016, 5:11:08 AM8/1/16
to dropwizard-user
t0tec, try this below and let me know

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

On Friday, 22 July 2016 16:51:35 UTC+1, t0tec wrote:
Reply all
Reply to author
Forward
0 new messages