How would I go about getting Jersey LoggingFilter working with logback? I saw this post:
How to get jersey logs at server?
but it unfortunately relies on the java.util.Logger
. I am not super well versed when it comes to web.xml configuration so I would not know how to go about offering the init-param
different loggers.
Note that I am using Spring 3 for dependency injection, but am creating loggers per class with the code:
Logger logger = LoggerFactory.getLogger(MyClass.class);
Hope this is enough information. If not, let me know.
My web container is Tomcat 7.0.12.
Slf4jLogger
fromorg.apache.cxf:cxf-core
package is another option. It implementsjava.util.logging.Logger
and delegate cals to slf4J.Jersey server:
Jersey client:
You can bridge
java.util.Logger
calls to Logback by using the jul-to-slf4j bridge. With that installed you can control Jersey logging (and any other JUL) with your logback.xml.I tried to use Jersey-Spring4 with logback and was not able to redirect access logs via the
LoggingFeature
to my logback-logger. The logback-logger was configured like<logger name="org.glassfish.jersey" level="INFO"/>
and I assumed this should do the trick.After I learned that Jersey is using JUL, I was sad for a few minutes and carried on with using
org.slf4j:jul-to-slf4j
. To make it work I had toin my
WebApplicationInitializer.onStartup(ServletContext servletContext)
.My
ResourceConfig
looked likeWhat logged access to the console. Removing the
ConsoleHandler
sadly did not end up in logs being logged to the logback-logger, the just got swallowed. But the red log statements on the console gave me the hint that this could beSTDERR
, albeit their wereINFO
.Finally LoggingFeature not logging correctly based on configuration on constructor gave me the missing piece.
My final and working
ResourceConfig
ended up asWhere
LoggingFeature.DEFAULT_LOGGER_NAME
andLevel.INFO
seem to be the crucial part.In the end I don't know exactly went wrong, but this is the result of my guessing and it works. If this helps anybody I am happy.