![](/img/trans.png)
[英]Does "Logging with slf4j at warn level", prevent the running "logger.debug(..."
[英]Is it possible for logger.debug to produce error if logging level is info
我是記錄器的新手,我只是想問如果我的日志級別是信息,我是否會收到錯誤,然后我有類似的東西:
logger.debug("hello " + object.getMethod());
它不在像下面這樣的 if 塊內:
if(LOGGER.isDebugEnabled){...}
此外,它是否會影響應用程序可能響應的時間。 如果它不在 if 塊語句中?
所有日志方法也在內部檢查級別。 如果為了性能,我們有isXYZEnabled
方法的原因。
考慮以下調用:
logger.debug("Value of myObject is: " + hugeObject.toString());
並假設hugeObject
對象,顧名思義,是巨大的。 構建它的字符串表示可能既耗時又耗內存,最終毫無意義,因為在創建字符串之后,如果級別未設置為調試,則不會記錄任何內容。 相反,您可以在執行此轉換之前明確檢查級別,並節省可能花費的時間:
if (logger.isDebugEnabled()) {
logger.debug("Value of myObject is: " + hugeObject.toString());
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.