使用slf4j來跟蹤信息。我的代碼是在slf4j中傳遞參數是否有正確的方法?
private static final Logger log = LoggerFactory.getLogger(ObjectTest.class);
log.trace("Time taken to store " + count
+ " objects of size " + size + " is " + (time) + " msecs");
log.trace("Time taken to store {} objects of size {} is {} msecs",
new Object[] { count, size, time });
log.trace("Time taken to store {} objects of size {} is {} msecs",
count, size, time);
這將是記錄跟蹤的首選機制。
的第二個。 –
3不編譯。然而,可變參數語法將允許3(如果我理解正確)。這個錯誤報告在http://bugzilla.slf4j.org/show_bug.cgi?id=31 –
如果這是一個真正的嚴格循環,並且性能很關鍵,那麼你應該將log命令包裝在if(log.isTraceEnabled ()){...'語句 – Yonatan