The time it takes to create objects in Java is negligible compared to string
concatenation. I'd strongly advice against creating custom logging wrappers,
they are rarely used consistently. Slf4j supports logging messages with
format and array of objects as parameters,
http://www.slf4j.org/apidocs/org/slf4j/Logger.html.

Kalle


On Wed, Mar 25, 2009 at 10:09 AM, Jeremy Haile <[email protected]> wrote:

> Without arguing either side, just be aware that with varargs, some of the
>> additional overhead is there even if debug is not enabled. That is, the
>> compiler turns the above into:
>>
>>  log.debug( "User with ID {0} logged into realm {1}", new Object[
>>> ]{userId, realm});
>>>
>>
>> which creates a new Object[ ] (that is garbage collected immediately), so
>> it's still not "free", even if it is less expensive than String
>> concatenation.
>>
>> Craig
>>
>
> Thanks Craig - hadn't thought about that.  Even if there is still a small
> performance penalty (the Object[] creation), it does significantly clean up
> the code.  I'm not strongly opinionated for or against it.  But I'd be more
> open to a custom logging wrapper that offers some value-adds like this vs.
> one that is simply just another wrapper layer.
>

Reply via email to