我应该使用slf4j isTraceEnabled吗? [英] should I be using slf4j isTraceEnabled or not?
问题描述
如果我打开大量数据以防启用跟踪,那么我应该使用 isTraceEnabled
或者只是执行我的 log.trace({} mymessage ,param)
在这种情况下使用 isTraceEnabled
还是没有任何好处?
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?
推荐答案
这取决于param
实际上是什么。如果它是一个复杂的表达式,最好使用 isTraceEnabled
。如果它只是对象的引用,则可以直接使用它。只有在启用跟踪时才会调用 toString
方法。
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.
使用 isTraceEnabled 如果连续有几个跟踪语句,code>也是有益的。您可以将它们放入相同的
if
然后。
Using isTraceEnabled
is also beneficial if you have several trace statements in a row. You can can put them into the same if
then.
这篇关于我应该使用slf4j isTraceEnabled吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!