blob: 86310865af8f5512755bf0a6ab521897fea6ac7b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
package tech.libeufin.util
import ch.qos.logback.classic.util.ContextInitializer
import ch.qos.logback.core.util.Loader
/**
* Set system properties to wanted values, and load logback configuration after.
* While it can set any system property, it is used only to set the log file name.
*
* @param logFile filename of logfile. If null, then no logfile will be produced.
* @param logFileNameAsProperty property that indicates the logfile name in logback configuration.
* @param configFileName name of logback's config file. Typically something different
* from "logback.xml" (otherwise logback will load it by itself upon startup.)
*/
fun setLogFile(logFile: String?, logFileNameAsProperty: String, configFileName: String) {
if (logFile != null) System.setProperty(logFileNameAsProperty, logFile)
val configFilePath = Loader.getResource(configFileName, ClassLoader.getSystemClassLoader())
if (configFilePath == null) {
println("Warning: could not find log config file")
}
System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, configFilePath.toString())
}
|