Link to home
Start Free TrialLog in
Avatar of LeanMoreTryMore
LeanMoreTryMore

asked on

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>
ASKER CERTIFIED SOLUTION
Avatar of Kannan Ekanath
Kannan Ekanath
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LeanMoreTryMore
LeanMoreTryMore

ASKER

Would you give me one of the sample java program which is under the com.ee ??
just want to get some idea. thanks
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");
    }
}
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
    }
}
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

:-?
> Maybe there is something I ignore

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

Yes - the title of the question ;-)
Thanks for all.
You are all very helpful
>> .... 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