When using embedded
jetty within an application, per default there is no support for
slf4j it is possible to redirect the logging to
log4j2. But without this redirection there is no way to directly use it. But of course there is a way to use it. Only a piece of simple adapter code is required.
Writing an adapter for the
jetty logging api
Jetty uses an own logging api that redirects logging events to a provided logging api. For that api a simple logging adapter is required. This adapter must extend the
org.eclipse.jetty.util.log.AbstractLogger. Before starting
org.eclipse.jetty.util.log.Log.setLog(AbstractLogger) must be invoked in order to replace the default logging mechanism of
In order to get the example simply checkout the source code or go to github.
Thanks, this is useful. However, I wouldn’t just swallow “IGNORE” level log events, they map nicely to the TRACE level of log4j2.
I think you’re absolutely right. I changed and pushed it to github. Thanks.
Hi Robert, thanks for the piece of code. I was exaclty looking for an answer. But i dont get what i need to do to get a full working set. What should i call in the main-method? And do i need a jetty.properties for the jetty-logger. My log4j2 works fine.
Haha, forget my question. It is just as you said: Log.setLog(new Jetty2Log4j2Bridge(“Jetty-Server”)); and everything works fine. Thank you.