@Sean Got it! I come from Java world so I guess I was wrong in assuming that arguments are evaluated during the method invocation time. How about the conditional checks to see if the log is InfoEnabled or DebugEnabled? For Example,
if (log.isInfoEnabled) log.info(msg) I hear we should use guard condition only when the string "msg" construction is expensive otherwise we will be taking a performance hit because of the additional "if" check unless the "log" itself is declared static final and scala compiler will strip away the "if" check and produce efficient byte code. Also log.info does the log.isInfoEnabled check inside the body prior to logging the messages. https://github.com/qos-ch/slf4j/blob/master/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLogger.java#L509 https://github.com/qos-ch/slf4j/blob/master/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLogger.java#L599 Please correct me if I am wrong. On Sun, Jun 25, 2017 at 3:04 AM, Sean Owen <so...@cloudera.com> wrote: > Maybe you are looking for declarations like this. "=> String" means the > arg isn't evaluated until it's used, which is just what you want with log > statements. The message isn't constructed unless it will be logged. > > protected def logInfo(msg: => String) { > > > On Sun, Jun 25, 2017 at 10:28 AM kant kodali <kanth...@gmail.com> wrote: > >> Hi All, >> >> I came across this file https://github.com/apache/spark/blob/master/core/ >> src/main/scala/org/apache/spark/internal/Logging.scala and I am >> wondering what is the purpose of this? Especially it doesn't prevent any >> string concatenation and also the if checks are already done by the library >> itself right? >> >> Thanks! >> >>