You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Gary Gregory <ga...@gmail.com> on 2015/03/03 03:16:59 UTC

Re: Missing Logger APIs for Throwables

I would say the current behavior is the least surprising because the API is
typed to an Object. But if I called a Throwable API I would expect the
stack trace.

Let's say we add Throwable APIs: Clearly if you recompile your sources,
you'll get the Throwable API.

What happens to clients compiled against 2.2 that would use a future 2.3
API? The compiler bound the call site to the Object API, will it change it
at runtime to a matching type of Throwable?

Gary

On Sat, Feb 28, 2015 at 1:14 AM, Remko Popma <re...@gmail.com> wrote:

> Hmm, good point. Would most users expect/want to log a stacktrace or the
> throwable toString when calling logger.trace(throwable)?
>
> One could argue for both, but perhaps the current behaviour is least
> surprising...
>
> Sent from my iPhone
>
> On 2015/02/28, at 13:59, Gary Gregory <ga...@gmail.com> wrote:
>
> Maybe I did not think this through...
>
> Today, if someone calls logger.trace(throwable), we log
> throwable.toString(). If we change that to logging a stack trace, it's a
> big change in behavior.
>
> The question is: Should we consider calling logger.trace(throwable) a bug
> if we log throwable.toString() instead of a stack trace?
>
> Gary
>
> On Fri, Feb 27, 2015 at 8:50 PM, Remko Popma <re...@gmail.com>
> wrote:
>
>> Sorry, I don't understand what you mean.
>>
>> If users want to log a stack trace they use logger.trace(throwable);
>> If they want to log the result of throwable.toString() they call
>> logger.trace(throwable.toString());
>>
>> Or am I missing something?
>>
>> Remko
>>
>>
>> On 2015/02/28, at 10:01, Gary Gregory <ga...@gmail.com> wrote:
>>
>> Yeah, that's a bit too clever and does not give you the option of
>> actually having a Throwable as an "Object" that will be toString()...
>>
>> Gary
>>
>> On Fri, Feb 27, 2015 at 4:41 PM, Remko Popma <re...@gmail.com>
>> wrote:
>>
>>> Nice catch! I just saw this happen at work, I agree we should do
>>> something about it.
>>>
>>> One solution would be to modify ObjectMessage.getFormattedString():
>>> If the object is an instance of Throwable then return the Throwable's
>>> stacktrace instead of its toString() result.
>>>
>>> I'm not a big fan of using instanceof, but it gives us a very compact
>>> solution.
>>>
>>> Thoughts?
>>>
>>> Sent from my iPhone
>>>
>>> On 2015/02/28, at 8:33, Gary Gregory <ga...@gmail.com> wrote:
>>>
>>> Hi All:
>>>
>>> I was just surprised (in a bad) way that calling:
>>>
>>> logger.trace(Throwable) compiles to the Object version of the API since
>>> we do not have a Throwable API.
>>>
>>> This means I am forced to do:
>>>
>>> logger.trace("Cause:", throwable);
>>>
>>> in order to see the stack trace.
>>>
>>> Thoughts on adding trace(Throwable)? (As well as the other levels)
>>>
>>> Gary
>>>
>>> --
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>> Java Persistence with Hibernate, Second Edition
>>> <http://www.manning.com/bauer3/>
>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>> Spring Batch in Action <http://www.manning.com/templier/>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>>
>>>
>>
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition
>> <http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory