Skip to content

Instantly share code, notes, and snippets.

@dkowis
Created November 19, 2014 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkowis/ba906337a2e787ddde2f to your computer and use it in GitHub Desktop.
Save dkowis/ba906337a2e787ddde2f to your computer and use it in GitHub Desktop.
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