If I print lot of data in case trace is enabled should i be using isTraceEnabled
or just do my log.trace("{} mymessage", "param")
would there be any benefit in this case to using isTraceEnabled
or no benefit?
That depends what "param"
actually is. If it is a complex expression it is better to use isTraceEnabled
. If it is just a reference to an object you can use it directly. Its toString
method will only be called if tracing is enabled.
Using isTraceEnabled
is also beneficial if you have several trace statements in a row. You can can put them into the same if
then.
While Henry's answer is correct, I wanted to add that trace
will effectively have to call isTraceEnabled
anyway, so there is actually a (very small) drawback to calling isTraceEnabled
when it isn't useful (i.e. you don't need to construct the parameters by non-trivial expressions and you only have a single trace
call).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With