Hi Kristian – yes, when adding two strings together, java does that
automatically because the new concatenated string is the actual parameter
you are passing, so it happens before you enter the log method. By using
the varargs calling convention, the concatenation is postponed until after
the method is entered.



Best regards,



Richard Sand | Managing Director
PO Box 91824 | Austin | Texas 78709-1824 | USA
Office: +1 888 612 8820 ext 02 | Fax: +1 866 304 3754
Mobile: +1 267 984 3651

[image: logo - small]



*From:* [email protected] [mailto:[email protected]] *On
Behalf Of *Kristian Lind
*Sent:* Thursday, February 07, 2013 4:36 PM
*To:* logback users list
*Subject:* Re: [logback-user] commons-logging -> sl4j -> logback



And that is of cause no matter if there is sl4j behind the commons-logging
I guess ?

On Thu, Feb 7, 2013 at 1:11 PM, Brett Walker <[email protected]>
wrote:

With log.debug("The object is " + object), it will always call .toString()
on object because the string argument needs to be constructed before the
call to .debug().



To avoid this use either



  If (log.isDebugEnabled()) {

    Log.debug("The object is " + object);

  }



Or the slf/logback usage



  Log.debug("The object is {0}", object);



Which will delay the call to .toString() until it has determined that debug
logging is needed.



Brett

Sent from my iPad


On 08/02/2013, at 7:43 AM, "Kristian Lind" <[email protected]> wrote:

In a previous project I switched from commons-logging -> log4j to sl4j ->
logback.
One of the reasons I did that was the overhead in log4j when providing a
object in the log...
log.debug("This is a object" + object);
would cause the object.toString to be called even debug was not enabled.

Now I work on a new project that uses commons-logging -> sl4j -> logback
(jcl-over-slf4j)

My question is now, will this still call object.toString.. even debug is
not enabled

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
....
log.debug("This is a object" + object);

I would like to get rid of commons-logging and jcl-over.sl4j and only have
sl4j and logback.





_______________________________________________
Logback-user mailing list
[email protected]
http://mailman.qos.ch/mailman/listinfo/logback-user


_______________________________________________
Logback-user mailing list
[email protected]
http://mailman.qos.ch/mailman/listinfo/logback-user





-- 
Med venlig hilsen / Best regards

Kristian Lind

<<image001.jpg>>

_______________________________________________
Logback-user mailing list
[email protected]
http://mailman.qos.ch/mailman/listinfo/logback-user

Reply via email to