How to get jersey logs at server?

后端 未结 5 1321
时光取名叫无心
时光取名叫无心 2020-11-28 05:36

I am using jersey for a REST WS. How do I enable jersey logs at server side?

Long story: I get a clientside exception - but I don\'t see anything in tomcat logs [It

5条回答
  •  臣服心动
    2020-11-28 05:54

    If you want to turn on logging on the server side, you need to register the LoggingFilter Jersey filter (on the container side).

    This filter will log request/response headers and entities.

    Here's what you need to add to your ResourceConfig class:

    @ApplicationPath("/")
    public class MyApplication extends ResourceConfig {
    
        public MyApplication() {
            // Resources.
            packages(MyResource.class.getPackage().getName());
    
            register(LoggingFilter.class);    
        }
    }
    

    Note that the same filter also works on the client side.

    Client client = Client.create();
    client.addFilter(new LoggingFilter());
    

提交回复
热议问题