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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
回答2:
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).