infrared
infrared

Reputation: 73

How to filter out Jetty DEBUG messages in slf4j/log4j2?

I just added an embedded Jetty/Jersey server to my application, which uses the log4j2 logging provider with slf4j bindings. The logging libraries are in the classpath and Jetty uses them, as described here:

https://www.eclipse.org/jetty/documentation/9.4.x/configuring-logging.html

This is a good thing, except that the DEBUG level in Jetty is very noisy, as also mentioned there.

I have three appenders (one console and two file) all at different levels, the file name for one of them is configured programmatically, besides that, the configuration is specified in the log4j2.properties file. So the setup is a little complicated, but it does exactly what I need.

Is there a simple way to convert the Jetty debug messages to trace before the message strings are processed and / or just to filter out the debug messages altogether based on the package name?

I don't expect that it's easy or or possible to convert the logging levels, but it doesn't hurt to ask.

And as far as filtering is concerned, in other words, I'd like to specify different levels depending on the package, INFO for org.eclipse.jetty and subpackages with TRACE as default, or TRACE for my package and subpackages with INFO as default. Ideally, this should be done in one place, but it doesn't have to be.

I'm still a little confused about about the loggers and appenders, so I got this to work partly by trial and error. For example, rootLogger.level doesn't seem to affect anything, so I'm guessing I can't specify filters through rootLogger. Some references I found suggest creating a logger with the name matching a specific class, but I'm not sure how that would work for this problem -- would it work with package/subpackage level filtering and, if so, would I need to create multiple loggers that could all write to same appenders?

Upvotes: 2

Views: 1575

Answers (2)

infrared
infrared

Reputation: 73

My interim solution is to change the rootLogger.level to info, which affects Jetty (org.eclipse.jetty) but not my code (net.....). The only other logger I have is a file logger, and it's named net, which seems to be the reason this works. Strangely, thie file logger affects the console output for my code, too, which works for me, but I don't understand why it works.

Upvotes: 0

Wei Kleeff
Wei Kleeff

Reputation: 308

How about give org.eclipse.jetty a logger and set to error level and additivity=false, and appender to console or another log, so it won't log to root logger to bother you.

<Appenders>        
    <Console name="Console" target="SYSTEM_OUT">
        <PatternLayout pattern="%-5p:[%c.class(%c{1}.java:%L)] %m%n"/>             
    </Console>                
</Appenders>

<Logger name="org.eclipse.jetty" level="error" additivity="false">            
    <AppenderRef ref="Console"/>
</Logger>

Upvotes: 5

Related Questions