Skip to content

Commit

Permalink
add a util method for changing the log level while running
Browse files Browse the repository at this point in the history
  • Loading branch information
holdenk committed Sep 17, 2014
1 parent 86d253e commit 44d6577
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions core/src/main/scala/org/apache/spark/util/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,14 @@ private[spark] object Utils extends Logging {
}
}

/**
* configure a new log4j level
*/
def setLogLevel(l: org.apache.log4j.Level) {
org.apache.log4j.Logger.getRootLogger().setLevel(l)
}


/**
* config a log4j properties used for testsuite
*/
Expand Down
12 changes: 11 additions & 1 deletion core/src/test/scala/org/apache/spark/util/UtilsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import com.google.common.base.Charsets
import com.google.common.io.Files
import org.scalatest.FunSuite

class UtilsSuite extends FunSuite {
import org.apache.spark.Logging

class UtilsSuite extends FunSuite with Logging {

test("bytesToString") {
assert(Utils.bytesToString(10) === "10.0 B")
Expand Down Expand Up @@ -297,4 +299,12 @@ class UtilsSuite extends FunSuite {
}
}

// Test for using the util function to change our log levels.
test("log4j log level change") {
Utils.setLogLevel(org.apache.log4j.Level.ALL)
assert(log.isInfoEnabled())
Utils.setLogLevel(org.apache.log4j.Level.ERROR)
assert(!log.isInfoEnabled())
assert(log.isErrorEnabled())
}
}

0 comments on commit 44d6577

Please sign in to comment.