Skip to content

Commit

Permalink
Make sure arg to logRaw and log are only eval'ed once.
Browse files Browse the repository at this point in the history
Stu pointed this out in https://rbcommons.com/s/twitter/r/2315/ after I submitted the PR.
The parameter `message` is passed by name, and so the argument might get evaluated in isFiltered() and in the logging function itself.
Also got rid of a deprecation warning for `ConsoleLogger.stdout`

Testing Done:
Patched in locally.

Bugs closed: 1655

Reviewed at https://rbcommons.com/s/twitter/r/2338/
  • Loading branch information
ericzundel committed Jun 12, 2015
1 parent 686eabd commit 8b89654
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/scala/org/pantsbuild/zinc/Util.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package org.pantsbuild.zinc

import java.io.File
import sbt.{ ConsoleLogger, Hash, IO, Level, Logger }
import sbt.{ ConsoleLogger, ConsoleOut, Hash, IO, Level, Logger }
import scala.util.matching.Regex

object Util {
Expand All @@ -21,20 +21,22 @@ object Util {
if (quiet) {
new SilentLogger
} else {
val out = ConsoleLogger.systemOut
val out = ConsoleOut.systemOut
val consoleLogger = ConsoleLogger(out = out, useColor = ConsoleLogger.formatEnabled && color); consoleLogger.setLevel(level)
new LoggerRaw() {
def isFiltered(message: => String): Boolean = {
filters.exists(_.findFirstIn(message).isDefined)
}
def trace(t: => Throwable): Unit = consoleLogger.trace(t)
def success(message: => String): Unit = consoleLogger.success(message)
def log(level: Level.Value, message: => String): Unit = {
def log(level: Level.Value, msg: => String): Unit = {
lazy val message = msg
if (!isFiltered(message)) {
consoleLogger.log(level, message)
}
}
def logRaw(message: => String): Unit = {
def logRaw(msg: => String): Unit = {
lazy val message = msg
if (!isFiltered(message)) {
out.print(message)
}
Expand Down

0 comments on commit 8b89654

Please sign in to comment.