Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded Jetty 9 Logging with Logback

I use jetty in a maven project and logging is already in place using slf4j and logback. Hence, I have a logback.xml where I configure logging and it works so far (format, setting levels for my project and libraries, ...).

However, now that I added jetty in the pom.xml as a dependency, I get tons of new DEBUG logs which I do not want to see (usually).

How can I set the log level for jetty to a higher level?

At the beginning, jetty reports that it recognized slf4j:

13:08:57 [main]      [DEBUG] log - Logging to Logger[org.eclipse.jetty.util.log] via org.eclipse.jetty.util.log.Slf4jLog

In my logback.xml, I tried to mute jetty as follows, but it does not work:

<logger name="org.eclipse.jetty" level="INFO" />

This does the trick for other libraries that I use.

I read the jetty documentation regarding logging, but they only document the use of standalone jetty - unfortunately, I was not able to adapt it for the embedded use case.

like image 403
Spiegelritter Avatar asked Mar 03 '26 07:03

Spiegelritter


1 Answers

I found the answer myself - it is slightly embarrassing. The issue is that there are two configuration files for logging: logback.xml and logback-test.xml.

I did not adjust the level of the logger in logback-test.xml which is used during development in a maven project. The logback.xml configuration, on the other hand, is used when a package is built, e.g. in production use.

From the logback documentation:

If you are using Maven and if you place the logback-test.xml under the src/test/resources folder, Maven will ensure that it won't be included in the artifact produced. Thus, you can use a different configuration file, namely logback-test.xml during testing, and another file, namely, logback.xml, in production.

Due to lack of experiences with logback and maven, I did not know this.

To conclude: Adding the following to the logback-test.xml solves my issue:

<logger name="org.eclipse.jetty" level="INFO" />
like image 74
Spiegelritter Avatar answered Mar 06 '26 02:03

Spiegelritter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!