Skip to content

Instantly share code, notes, and snippets.

@tomasherman
Created June 27, 2011 10:55
Show Gist options
  • Save tomasherman/1048670 to your computer and use it in GitHub Desktop.
Save tomasherman/1048670 to your computer and use it in GitHub Desktop.
Scala off the record logging
trait Logging {
def offTheRecords[A](f: => A):A = {
val lvl = loggingLevel // loggingLevel returns current logging leve;
disableLogging()
val result = f //invokes off-the-records function
setLoggingLevel(lvl) //undo of the disableLogging call
result
}
}
usage:
class SimplePluginManagerSpec extends Specification{
val testDir = new File(this.getClass.getResource("/plugin/PluginDefinitionLoading/plugins").toURI)
val pm = new SimplePluginManager //class mixed with Logging trait
"Simple plugin manager" should {
"load plugins" in {
pm.offTheRecords(
{
pm.bootupPlugins(testDir) must_== List[Plugin](new DummyPlugin) //expect exceptions being throw and logged, don't want to see that during testing so i shall silence it
}
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment