logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: log.info prints exceptios
Date Tue, 06 Nov 2007 18:34:01 GMT

On Nov 6, 2007, at 2:12 AM, Amnon Lahav wrote:

> thanks for your detailed answer curt , that was my mistake i was  
> under the
> impression that treshold specifies the only level which will be  
> printed out
> .
> if i  understand right from what i've read in order to use filters  
> i must
> switch to a log4j xml configurations .

I believe that is correct.

> i avoided the ("message",e) type because i tough i'll only be getting
> exceptions there (error.log) so i won't need the "explanation"  
> it'll appear
> in the stacktrace , but as i allso found out the exception gets  
> printed out
> as a stacktrace only in the info log and not the error log whre is  
> only
> printed out as a e.getMessage() type , why is that happening ?
> thanks .

The message (first) parameter is declared as an Object and somewhere  
later it is expected that its toString() method will be called to get  
the text actually used as the message.  The message parameter is  
commonly a String (and String.toString() returns itself).  So the  
following are all reasonable:

logger.info("Hello, World");
logger.info(new StringBuffer("Hello, World"));
logger.info(new Double(Math.PI));

In each case, somewhere in processing the object's toString() method  
is called to get the text message.  There is no special treatment for  
an exception.  At the same place, Double.toString() would be called,  
Exception.toString() is called.  There is no code in log4j that's like:

if (msg instanceof Throwable) {
     //   I know that the user really wanted to see the output of  
    renderedMessage = ...
} else if (msg instanceof SomeOtherSpecialClass) {
    renderedMessage = ...
} else {
    //    if not any special case that we likely never documented
    //       then call toString() to get the rendered message
    renderedMessage = msg.toString();

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message