dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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

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

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

Amit Shah
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

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