Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i avoid logging jersey WebApplicationExceptions?

Tags:

java

jersey

Using jersey, i throw a WebApplicationException with a 503, indicating that my service is unavailable (because some downstream service is unavailable).

When this happens, i get logging that looks like the below, with a huge stack trace.

[exec] SEVERE: Mapped exception to response: 503 (Service Unavailable)
[exec] javax.ws.rs.WebApplicationException
...

I don't really want this logging, since it actually ends up tying up the server's threads due to too much logging. Eg, i find many threads stuck in the below. Is there any way to just tell jersey to not log anything, or at least not log the stack trace? Note that i do want this logging for other error codes, like a 500. Just not 503's.

at java.util.logging.StreamHandler.publish(StreamHandler.java:174)
- waiting to lock <0x00000000c30ef5e0> (a java.util.logging.ConsoleHandler)
at java.util.logging.ConsoleHandler.publish(ConsoleHandler.java:88)
at java.util.logging.Logger.log(Logger.java:478)
at java.util.logging.Logger.doLog(Logger.java:500)
at java.util.logging.Logger.log(Logger.java:589)
at com.sun.jersey.spi.container.ContainerResponse.logException(ContainerResponse.java:509)
at com.sun.jersey.spi.container.ContainerResponse.onException(ContainerResponse.java:487)
at com.sun.jersey.spi.container.ContainerResponse.mapWebApplicationException(ContainerResponse.java:421)
at com.sun.jersey.spi.container.ContainerResponse.mapMappableContainerException(ContainerResponse.java:399)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1418)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
like image 229
Jack Avatar asked Nov 12 '22 18:11

Jack


1 Answers

What worked for me was to simply turn off all logging for that class. SLF4J provides an "OFF" level, which suppresses all logging.

In my Dropwizard config:

loggers:
  "com.sun.jersey.spi.container.ContainerResponse": OFF

Perhaps not the most elegant solution, but I couldn't handle those stack traces polluting my logs anymore.

like image 180
Eric Anderle Avatar answered Nov 15 '22 06:11

Eric Anderle