Skip to content

Commit

Permalink
[trivial] Event sink default should match root logger level
Browse files Browse the repository at this point in the history
Problem

EventSink defaults to capturing the root logger at Level.ALL.  This is
problematic because some log messages are computed lazily, and it would
be too easy to unwittingly force these messages with EventSink's
defaults.

Solution

Match the log level of the root logger. This is what service owners
would set to a reasonable default.

RB_ID=639266
  • Loading branch information
luciferous authored and jenkins committed Apr 22, 2015
1 parent 971da72 commit 8a00559
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions util-logging/src/main/scala/com/twitter/logging/Logger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ object Level {
private[logging] val AllLevels: Seq[Level] =
Seq(OFF, FATAL, CRITICAL, ERROR, WARNING, INFO, DEBUG, TRACE, ALL)

/**
* Associate [[java.util.logging.Level]] and `Level` by their integer
* values. If there is no match, we return `None`.
*/
def fromJava(level: javalog.Level): Option[Level] =
AllLevels.find(_.value == level.intValue)

/**
* Get a `Level` by its name, or `None` if there is no match.
*/
def parse(name: String): Option[Level] = AllLevels.find(_.name == name)
}

Expand Down
18 changes: 18 additions & 0 deletions util-logging/src/test/scala/com/twitter/logging/LoggerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,24 @@ class LoggerTest extends WordSpec with TempFolder with BeforeAndAfter {
}
}

"Levels.fromJava" should {
"return a corresponding level if it exists" in {
assert(Level.fromJava(javalog.Level.OFF) == Some(Level.OFF))
assert(Level.fromJava(javalog.Level.SEVERE) == Some(Level.FATAL))
// No corresponding level for ERROR and CRITICAL in javalog.
assert(Level.fromJava(javalog.Level.WARNING) == Some(Level.WARNING))
assert(Level.fromJava(javalog.Level.INFO) == Some(Level.INFO))
assert(Level.fromJava(javalog.Level.FINE) == Some(Level.DEBUG))
assert(Level.fromJava(javalog.Level.FINER) == Some(Level.TRACE))
assert(Level.fromJava(javalog.Level.ALL) == Some(Level.ALL))
}

"return None for non corresponding levels" in {
assert(Level.fromJava(javalog.Level.CONFIG) == None)
assert(Level.fromJava(javalog.Level.FINEST) == None)
}
}

"Levels.parse" should {
"return Levels for valid names" in {
assert(Level.parse("INFO") == Some(Level.INFO))
Expand Down

0 comments on commit 8a00559

Please sign in to comment.