Search code examples
javalogginghtmlunitlogback

preventing HTMLUnit log system to interfere with Logback


I'm making a switch from Log4j to Logback. I'm using HTMLUnit for my project and when I was using Log4j I had to add the 2 lines below to prevent HTMLUnit log messages interfere with my configuration.

log4j.logger.com.gargoylesoftware.htmlunit=ERROR
log4j.logger.org.apache.http=ERROR

Here is my current Logback configuration

<configuration>
    <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
        <connectionSource
            class="ch.qos.logback.core.db.DriverManagerConnectionSource">
            <driverClass>org.postgresql.Driver</driverClass>
            <url>jdbc:postgresql://MYIP:5432/logs</url>
            <user>logs</user>
            <password>MYPASS</password>
        </connectionSource>
    </appender>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%msg%n</pattern>
        </encoder>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="DB" />
        <appender-ref ref="STDOUT" />
    </root>

</configuration>

I'm now using an xml style configuration file for Logback. What is the equivalent of the lines above for the xml Logback configuration?


Solution

  • You can explicitly specify the level of loggers in the logback configuration like so:

    <logger name="com.gargoylesoftware.htmlunit" level="ERROR" />
    <logger name="org.apache.http" level="ERROR" />