mirror of
https://github.com/digital-asset/daml.git
synced 2024-10-26 05:09:36 +03:00
Simplify loading of logback file (#10592)
* Simplify loading of logback file doConfigure accepts a URL which slightly simplifies things. Really the primary reason why I’m doing this is that it gets veracode to shut up. I don’t fully understand what it’s worried about in the first place but it looks like it gets angry about calling openStream on the resource *shrug* changelog_begin changelog_end * fix 2.12 build changelog_begin changelog_end
This commit is contained in:
parent
19bfdbee00
commit
01b8e3011f
@ -16,11 +16,6 @@ da_scala_library(
|
||||
],
|
||||
scalacopts = lf_scalacopts,
|
||||
tags = ["maven_coordinates=com.daml:http-json-cli-opts:__VERSION__"],
|
||||
versioned_scala_deps = {
|
||||
"2.12": [
|
||||
"@maven//:org_scala_lang_modules_scala_collection_compat",
|
||||
],
|
||||
},
|
||||
visibility = ["//visibility:public"],
|
||||
runtime_deps = [
|
||||
"@maven//:org_codehaus_janino_janino",
|
||||
|
@ -12,29 +12,26 @@ object Logging {
|
||||
import ch.qos.logback.core.joran.spi.JoranException
|
||||
import ch.qos.logback.classic.LoggerContext
|
||||
import ch.qos.logback.classic.joran.JoranConfigurator
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
import org.slf4j.LoggerFactory
|
||||
import scala.util.Using
|
||||
import java.io.InputStream
|
||||
import java.io.FileInputStream
|
||||
def reloadConfig(path: String, openStream: String => InputStream): Unit =
|
||||
Using.resource(openStream(path)) { stream =>
|
||||
try {
|
||||
val context = LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext]
|
||||
val configurator = new JoranConfigurator()
|
||||
configurator.setContext(context)
|
||||
context.reset()
|
||||
configurator.doConfigure(stream)
|
||||
} catch {
|
||||
case je: JoranException =>
|
||||
// Fallback to System.err.println because the logger won't work in any way anymore.
|
||||
System.err.println(
|
||||
s"reconfigured failed using url $path: $je"
|
||||
)
|
||||
} finally stream.close()
|
||||
def reloadConfig(path: URL): Unit =
|
||||
try {
|
||||
val context = LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext]
|
||||
val configurator = new JoranConfigurator()
|
||||
configurator.setContext(context)
|
||||
context.reset()
|
||||
configurator.doConfigure(path)
|
||||
} catch {
|
||||
case je: JoranException =>
|
||||
// Fallback to System.err.println because the logger won't work in any way anymore.
|
||||
System.err.println(
|
||||
s"reconfigured failed using url $path: $je"
|
||||
)
|
||||
}
|
||||
System.getProperty("logback.configurationFile") match {
|
||||
case null => reloadConfig("logback.xml", clazz.getClassLoader.getResource(_).openStream())
|
||||
case path => reloadConfig(path, new FileInputStream(_))
|
||||
case null => reloadConfig(clazz.getClassLoader.getResource("logback.xml"))
|
||||
case path => reloadConfig(new File(path).toURI().toURL())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user