On Sunday, June 5, 2016 at 7:39:25 PM UTC+9, Philippe Marschall wrote:
>
>
>
> On Friday, June 3, 2016 at 5:50:36 PM UTC+2, Remko Popma wrote:
>>
>>
>>
>> On Friday, June 3, 2016 at 4:42:51 PM UTC+9, Philippe Marschall wrote:
>>>
>>>
>>>
>>> On Tuesday, May 17, 2016 at 7:13:09 PM UTC+2, Remko Popma wrote:
>>>>
>>>> Hi all,
>>>>
>>>> First, my thanks to the many people who gave helpful advice and 
>>>> feedback on how to measure Log4j response time on this list some time ago.
>>>>
>>>> We're about to start the Log4j 2.6 release.
>>>> If anyone is interested, a preview of the garbage-free logging manual 
>>>> page is here: 
>>>> http://home.apache.org/~rpopma/log4j/2.6/manual/garbagefree.html
>>>> and a preview of the updated performance page is here: 
>>>> http://home.apache.org/~rpopma/log4j/2.6/performance.html
>>>>
>>>
>>> Forgive me my ignorance. Maybe I'm missing something or misunderstanding 
>>> something. If I want to a custom domain object like this
>>>
>>> LOG.info("something happened with {}", aDomainObject);
>>>
>>> then #toString() will be called on that object which very likely will 
>>> result in allocation. If I don't want this my domain object has to 
>>> implement CharSequence. I image this to be quite though to do without 
>>> allocation eg. how can I know the value of #charAt(10)? I would have to 
>>> "render" the entire object without allocation for every #charAt call.
>>>
>>> What I would really need is an alternative to #toString() that takes an 
>>> Appendable. Ideally that would be a JDK interface.
>>>
>>> public interface Loggable {
>>>
>>>   void logTo(Appendable log);
>>>
>>> }
>>>
>>
>> Philippe, I completely agree. The only thing is that no such interface 
>> exists in the JDK, so Log4j 2.6 includes a custom interface:
>>
>> package org.apache.logging.log4j.util;
>> public interface StringBuilderFormattable {
>>     /**
>>      * Writes a text representation of this object into the specified {@code 
>> StringBuilder},
>>      * ideally without allocating temporary objects.
>>
>>      *
>>      * @param buffer the StringBuilder to write into
>>      */
>>     void formatTo(StringBuilder buffer);
>> }
>>
>>  
>> We chose StringBuilder because the Appendable API is not rich enough.
>> Any Object that is logged, either standalone or as a parameter, if it 
>> does not implement CharSequence but it does 
>> implement StringBuilderFormattable then Log4j 2.6 will call 
>> formatTo(StringBuilder) instead of toString() on it. You can use this to 
>> render the domain object to text without creating temporary objects.
>>
>> I hope this is useful.
>>
>
> This is exactly what I'm looking for, I somehow missed that part at the 
> bottom. Thank you for our work, hopefully this will get more exposure in 
> the future.
>
My fault: this was not properly documented. I've updated the docs and we 
will update the site with the upcoming 2.6.1 bugfix release.
Glad this is useful, feedback and feature requests always welcome! -Remko 

>
> Cheers
> Philippe 
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org

Reply via email to