简体   繁体   中英

How do I disable logging in Jersey 2.x

Currently I'm running Jersey 2.14 (and Grizzly 2.16), though I don't see much difference in newer/older versions regarding logging.

I'm trying to disable message like the following:

INFO: 2 * Server responded with a response on thread Grizzly-worker(15)
2 < 201
2 < Location: somewhere

From whenever I do, well, anything in a production environment. I even have a barebones class that I thought would hide the method for client and server:

@Provider
public class MyLoggingFilter extends LoggingFilter
{
    @Override
    public void filter(ClientRequestContext context) throws IOException
    {
        // Do nothing.
        //super.filter(context);
    }
}

and

@Provider
public class MyLoggingFilter extends LoggingFilter
{
    @Override
    public void filter(ContainerRequestContext context) throws IOException
    {
        // Do nothing.
        //super.filter(context);
    }
}

It should be noted that these methods are getting hit, as I found out via trace statements.

Is there some ServerProperty, or other toggleable option, I'm not seeing that is responsible for this so I can turn this off during production?

Thanks!

I found the solution: Because of the

@Provider

decoration, the LoggingFilter was being registered automatically. By removing it, I was able to control the logging and thus disable the logging messages.

Check your web.xml and/or Application class. Jersey logging filter if added in web.xml will be:

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

If configured as a Application class it will be included in the class extending org.glassfish.jersey.server.ResourceConfig.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM