Skip to content

Instantly share code, notes, and snippets.

@dkowis

dkowis/wrapped.scala

Created Nov 19, 2014
Embed
What would you like to do?
An example to wrap it instead of copy/pasting try/finally on each one. Same effect as calling a function in try/finally, but you can do more
def withContext(f: LoggingServiceImpl => Unit) = {
val loggingService = new LoggingServiceImpl()
val context = LogManager.getContext(false).asInstanceOf[LoggerContext]
try {
f(loggingService)
} finally {
System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_FACTORY)
context.reconfigure
StatusLogger.getLogger.reset
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment