Created
June 27, 2011 10:55
-
-
Save tomasherman/1048670 to your computer and use it in GitHub Desktop.
Scala off the record logging
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
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