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


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

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