Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Java
Expertise: Intermediate
Feb 8, 2006



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Suppress Logs from Libraries

How many times have you tried to get rid of the intrusive log messages from the API you're using?

The solution is easy: in your log4j configuration file, just include a logger name for the vendor and suppress their log messages. Here's an example:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration debug="true">
    <appender name="MAIN" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File" value="./logs/main.log"/>
        <param name="Append" value="true"/>
        <param name="DatePattern" value=".yyyy-MM-dd-a"/>
        <param name="Threshold" value="DEBUG"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
                   value="%d{HH:mm:ss,SSS} %-20c:%20M : %m%n"/>

    <logger name="org.springframework">
        <level value="ERROR"/>

        <level value="DEBUG"/>
        <appender-ref ref="MAIN"/>
The above example uses DEBUG-level logging for all of the code and suppresses any log messages below ERROR-level from springframework.

Amit Shah
Thanks for your registration, follow us on our social networks to keep up-to-date