aboutsummaryrefslogtreecommitdiff
path: root/util/src/main/kotlin/Config.kt
diff options
context:
space:
mode:
authortanhengyeow <E0032242@u.nus.edu>2020-06-24 20:21:54 +0800
committertanhengyeow <E0032242@u.nus.edu>2020-06-24 20:21:54 +0800
commit530c8b9394abff9023d2885736003b886a5f5714 (patch)
treed918fb211f1431205cb2ce9870da9a57b86ebca0 /util/src/main/kotlin/Config.kt
parent7884146d6e3a159ee9bf2b0eec2b09210c1ce75e (diff)
parent3c50e816038d0efa289329f286cb81ac31fbbeee (diff)
downloadlibeufin-530c8b9394abff9023d2885736003b886a5f5714.tar.gz
libeufin-530c8b9394abff9023d2885736003b886a5f5714.tar.bz2
libeufin-530c8b9394abff9023d2885736003b886a5f5714.zip
Merge branch 'master' of ssh://git.taler.net/libeufin
Diffstat (limited to 'util/src/main/kotlin/Config.kt')
-rw-r--r--util/src/main/kotlin/Config.kt22
1 files changed, 22 insertions, 0 deletions
diff --git a/util/src/main/kotlin/Config.kt b/util/src/main/kotlin/Config.kt
new file mode 100644
index 00000000..86310865
--- /dev/null
+++ b/util/src/main/kotlin/Config.kt
@@ -0,0 +1,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())
+} \ No newline at end of file