log4j.xml - can i configure to see the warning message only

I use the following log4j.xml. My question is there is too much infomration shown in the log file.
My question is how can i configure the log4j to just display certain information such warning or info

Thanks in advance

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <appender name="myAppender" class="org.apache.log4j.FileAppender">
       <param name="File" value="my.log"/>
       <layout class="org.apache.log4j.SimpleLayout"/>
    </appender>    
   
    <root>
        <priority value="debug" />
        <appender-ref ref="myAppender"/>
    </root>
</log4j:configuration>
LeanMoreTryMoreAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kannan EkanathCommented:
I will show you a simple example where all classes under "com.ee.*" have their warning messages in one log.
    <category name="com.ee" additivity="false">
        <priority value="WARN"/>
        <appender-ref ref="EE-LOG"/>
    </category>

    <appender name="EE-LOG" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="C:/IWB/logs/spring.log"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%5p %d{dd-MMM-yy HH:mm:ss} %c: %m%n"/>
        </layout>
    </appender>

Idea is simple, you declare a category of classes and a level, then associate an appender with that category. Simple :-D

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LeanMoreTryMoreAuthor Commented:
Would you give me one of the sample java program which is under the com.ee ??
just want to get some idea. thanks
Kannan EkanathCommented:
http://logging.apache.org/log4j/docs/manual.html

***********************************************
package com.ee;

Class MyExample {
    static final Logger logger = Logger.getLogger(MyExample.class.getName());

    void someInterestingMethod() {
        logger.warn("I am going to do something interesting");
        //actually do something interesting
        logger.warn("I did somethign really interesting");
    }
}
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Kannan EkanathCommented:
The above example is a very crude way of saying typically in some method like placingOrder,
Class MyExample {
    static final Logger logger = Logger.getLogger(MyExample.class.getName());

    void placeOrder(Customer customer) {
        if(customer.isCreditLimitDangerous()) {
               logger.warn("Placing an order for the customer ["+ customer + "] is potentially dangerous.");
        }
        //place order here
    }
}
Giant2Commented:
>just display certain information such warning or info

change you line of your log4j.xml
from
      <priority value="debug" />
to
      <priority value="INFO" />

and restart the application where you use it.
From that moment the log of type: INFO, WARN, ERROR and FATAL will be displayed.

Bye, Giant.
CEHJCommented:
>>can i configure to see the warning message only

Yes

<appender name="EE-LOG" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="C:/IWB/logs/spring.log"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%m%n"/>
        </layout>
    </appender>
Giant2Commented:
CEHJ,
the question was:
>My question is how can i configure the log4j to just display certain information such warning or info
and not
>can i configure to see the warning message only

Maybe there is something I ignore, but I do not understand.

:-?
Mick BarryJava DeveloperCommented:
> Maybe there is something I ignore

Would seem more CEHJ ignoring what was asked :)
CEHJCommented:
>>Maybe there is something I ignore

Yes - the title of the question ;-)
LeanMoreTryMoreAuthor Commented:
Thanks for all.
You are all very helpful
CEHJCommented:
>> .... have their warning messages in one log.

There's no need to atomise you log file like that. If you want to inspect only warnings, given Windows, you can simply do

type your.log | find "WARN" >temp-warn.log

then delete the file temp-warn.log when you've finished looking
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.