users@jersey.java.net

[Jersey] Re: how to disable the logging of a Jersey Client.

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Mon, 27 Jun 2011 13:43:28 +0200

Hello Pengfei,

you should try this:
http://download.oracle.com/javase/1.4.2/docs/guide/util/logging/overview.html#1.8

(always worked for me).

Additionally, your code most likely should work too, but you need to
obtain correct one: ClientResponse.class =
"com.sun.jersey.api.client.ClientResponse". AFAIK it does not
automatically take all "hierarchical" successors, because from semantic
view .. its just a name. (Hierarchy can be used in config file though,
so something like "com.sun.jersey.*" should work there.

Hope it helps,
Pavel

On 6/21/11 12:48 PM, Pengfei Di wrote:
> Hello,
>
> we have a problem disabling logging. The situation is as follows:
>
> We have a JUnit test that makes a big amount of requests to our REST
> API. Cause we may throw an exception on the server (due to wrong /
> parameters) we have an ErrorModel and and exception mapper for that.
> Now it can happen that we have accidently have no error model while
> there should be one (negative tests) or that there is none while there
> should be one (positive tests). Thus we can not avoid trying to get an
> ErrorModel with
>
> response.getEntity( ErrorModelWithoutStatus.class ); /* response is an
> instance of ClientResponse */
>
> but that leads to ClientResponse.getEntity(Class<T> c, Type type) with
> the unavoidable logging of an error message due to
>
> ...
> String message = "A message body reader for Java class " + c.getName() +
> ", and Java type " + type +
> ", and MIME media type " + mediaType + " was not
> found";
> LOGGER.severe(message);
> Map<MediaType, List<MessageBodyReader>> m =
> workers.getReaders(mediaType);
> LOGGER.severe("The registered message body readers
> compatible with the MIME media type are:\n" +
> workers.readersToString(m));
>
> throw new ClientHandlerException(message);
>
> (in Jersey 1.6, class ClientResponse, method .getEntity(Class<T> c, Type
> type), behaviour seems to be the same in Jersey 1.7)
>
>
> So there are cases where we expect the thrown ClientHandlerException and
> catch them accordingly but we can not prevent the misleading logging. So
> how can we avoid the logging?
> Trying init-param in web.xml failed, trying configuring log4j.xml
> failed, even trying
>
> private final static Logger COM_SUN_JERSEY_LOGGER = Logger.getLogger(
> "com.sun.jersey" );
> private final static java.util.logging.Logger COM_SUN_JERSEY_LOGGER2 =
> LogManager.getLogManager( ).getLogger( "com.sun.jersey" );
>
> static
> {
> COM_SUN_JERSEY_LOGGER.setLevel( Level.OFF );
> COM_SUN_JERSEY_LOGGER2.setLevel(java.util.logging.Level.OFF);
> }
>
> failed.
>
> With kind regards
>
> Sebastian / Pengfei
>