users@jersey.java.net

[Jersey] Re: How to configure Jersey to automatically log all exceptions?

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Wed, 31 Oct 2012 19:37:24 +0100

Jersey will log all the unhandled exceptions, but we do not have a configurable logging. We rely on standard Java SE Logging API. To configure Jersey logging, in Jersey 1.x the logger root is "com.sun.jersey", in Jersey 2.x it is "org.glassfish.jersey".

...but in your case I would still opt for the try-catch block in your resource. If you have more such resources or methods, another alternative would be to convert your resources to CDI-managed beans and provide a CDI method interceptor that would do the logging (obviously you'll need to run in a CDI-enabled environment).

Marek


On Oct 30, 2012, at 2:59 PM, "Ryabin, Thomas" <Thomas.Ryabin_at_McKesson.com> wrote:

> Hi,
>
> I have a Jersey service that can throw various kinds of exceptions, and I would like to log every exception thrown along with its stacktrace. One way I could do this is to just surround the service method in a try/catch clause and log the exceptions that way. Could I configure Jersey to automatically log all exceptions thrown and avoid using a try/catch clause? I am using Logback as my logging framework, so I would like to be able to configure where the exceptions are logged by editing the logback.xml file.
>
> -Thomas