簡體   English   中英

Scala中日志記錄的相對性能影響

[英]Relative performance impact of logging in Scala

我已經看到了以下記錄方式。 每種對運行時性能有何影響? 使用另一種方法還有其他好處嗎?

val strValue = "xyz"
val intValue = 200

log.debug("This will log the string " + strValue + " and the int " + intValue) 

log.debug(s"This will log the string $strValue and the int $intValue" )  

log.debug("This will log the string %s and the int %d".format(strValue,intValue))

log.debug("This will log the string {} and the int {}", strValue, intValue) 

我當前的大多數日志記錄需求都在Play和Akka項目中。

我認為演出的影響沒有差別 第二和第三種方法應該完全相同。 Scala編譯器將第二個轉換為第三個。 第二個只是提供了更好的語法。

話雖如此,那些日志語句應該對性能沒有任何影響。 這些日志語句將轉換為以下內容。 因此,它自動遵循您可能從Java中了解的最佳實踐。

if(log.isDebugEnabled()){
  log.debug(...)
}

所以最后:堅持最喜歡的東西:-)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM