-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[split] util-logging: Gets correct method and class name in c.t.u.Log…
…Record RB_ID=248087
- Loading branch information
Showing
5 changed files
with
115 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
util-logging/src/test/scala/com/twitter/logging/LogRecordTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.twitter.logging | ||
|
||
import java.util.logging.{Level => JLevel, LogRecord => JRecord} | ||
import org.junit.runner.RunWith | ||
import org.scalatest.FunSuite | ||
import org.scalatest.junit.JUnitRunner | ||
|
||
@RunWith(classOf[JUnitRunner]) | ||
class LogRecordTest extends FunSuite { | ||
test("LogRecord should getMethod properly") { | ||
Logger.withLoggers(Nil) { | ||
new LogRecordTestHelper({ r: JRecord => r.getSourceMethodName() }) { | ||
def makingLogRecord() { | ||
logger.log(Level.INFO, "OK") | ||
assert(handler.get === "makingLogRecord") | ||
} | ||
makingLogRecord() | ||
} | ||
} | ||
} | ||
|
||
test("LogRecord should getClass properly") { | ||
Logger.withLoggers(Nil) { | ||
new Foo { | ||
assert(handler.get === "com.twitter.logging.Foo") | ||
} | ||
} | ||
} | ||
} | ||
|
||
abstract class LogRecordTestHelper(formats: JRecord => String) { | ||
val formatter = new Formatter { | ||
override def format(r: JRecord): String = formats(r) | ||
} | ||
val handler = new StringHandler(formatter) | ||
val logger = Logger.get("") | ||
logger.addHandler(handler) | ||
} | ||
|
||
class Foo extends LogRecordTestHelper({ r: JRecord => r.getSourceClassName() }) { | ||
def makingLogRecord() { | ||
logger.log(Level.INFO, "OK") | ||
} | ||
|
||
makingLogRecord() | ||
} |