Spiegelritter
Spiegelritter

Reputation: 856

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.

Upvotes: 3

Views: 4474

Answers (1)

Spiegelritter
Spiegelritter

Reputation: 856

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" />

Upvotes: 7

Related Questions