I have a rest service developed with jersey, I have a ContainerRequestFilters for print the request, as follows:
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
<param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
</init-param>
and I have logger in the post methods using log4j. But the LoggingFilter print in the log different log4j. Is there any way that LogginFilter use the log4j's configuration?
I tried this in the log4j.xml file:
<logger name="com.sun.jersey.api.container.filter.LoggingFilter">
<level value="info" />
<appender-ref ref="ROOT" />
<appender-ref ref="CONSOLE" />
</logger>
but it don't work :(
This will allow you to use any logger you want.
Implementation
Abstract Logging Filter Class
This is straight from the Jersey Logging filter class but making the log method abstract.
Register it the same way as ususal.
Jersey uses indeed the jdk logger. You can use the SLF4JBridgeHandler to transfer the JDK log messages to your logging infrastructure. (see Claus Nielsen's Blogpost)
So to get this picked up in your Spring application, I used the
@PostConstruct
annotation.One way to handle this is to write a filter for the java logger where you simply log to message with the log4j logger, or which ever you prefer and you sink the java logging by always returning false.
As of log4j2, you can simply hand over all of JDK's logging to log4j (unless you explicitly require JDK logging to handle part of the rest of the logging), using the
log4j-jul
library and the-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
VM argument.Source: https://logging.apache.org/log4j/2.0/log4j-jul/