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: DailyFileAppender exception
Date Thu, 16 Feb 2006 00:12:19 GMT

On Feb 15, 2006, at 5:39 PM, Kamal Ahmed wrote:

> Curt,
> Yes, you are absolutely right , this is a unit test, and line 43:
> Throwable e = new Throwable("exception");
> Needs to be there since I need to manually create a LoggingEvent,  
> which
> needs a Throwable object.

In client code (that is code that is just using log4j) it is  
unnecessary to create a LoggingEvent, one will be created by the  
Logger in response to a call to Logger.debug() and similar methods.   
If you do need to create a LoggingEvent (for example, in a unit test  
to test your custom appender), it is not necessary to construct a  
Throwable since you can pass null for that parameter on the  
LoggingEvent constructor.  From the description of your unit test, it  
appears that you are calling methods similar to what would occur in  
the following snippet of client

try {
    //   do something that might throw an exception
} catch(Exception e) {
     logger.debug("Hello, World", e);

In that case, a LoggingEvent would be constructed with a message  
"Hello, World" and would contain the exception.  Most layouts would  
result in the user supplied message ("Hello, World") and then the  
message and stack trace of the exception.  log4j does not appear to  
be throwing an exception, it just appears to be reporting an  
exception that you requested it to log. 

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

View raw message