Logging Uncaught Exceptions Is Not Working

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Logging Uncaught Exceptions Is Not Working

Casey O'Neill
I appear to be having an issue with logging uncaught exceptions and I was hoping that someone might be able to point me in the right direction. When my Resource method throws an unexpected and uncaught exception I'm failing to see those exceptions in my logging system. In my particular case, these errors are not showing in Sentry.io. I've been debugging this for a bit and I believe it might be due to an implementation bug in Jersey2. 

I'm setting up the LoggingFeature in my ResourceConfig like so:

Logger rootLogger = LogManager.getLogManager().getLogger("");
register(new LoggingFeature(rootLogger, Level.WARNING, null, null));

With that setting all Jersey request and response data is of course logged at the WARNING level. However, even with setting the LoggingFeature level to WARNING, the uncaught exception is logged with a level of DEBUG. That appears to be coming from org.glassfish.jersey.server.ServerRuntime.process() line 506 in version 2.25:

LOGGER.log(Level.FINE, LocalizationMessages.ERROR_EXCEPTION_MAPPING_THROWN_TO_CONTAINER(), responseError);

The resulting output is of course at the DEBUG level:

2017-01-25 13:44:19,627 [qtp1531063109-43] DEBUG org.glassfish.jersey.server.ServerRuntime$Responder

Does anyone know why we are logging all uncaught exception at the DEBUG level instead of at the proper ERROR or WARNING level? Am I missing something? Is there a reason that the JerseyProcessingUncaughtExceptionHandler is not being invoked?