gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: nexus offers logfile name among option


From: gnunet
Subject: [libeufin] branch master updated: nexus offers logfile name among options
Date: Wed, 24 Jun 2020 11:52:18 +0200

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 6044b5c  nexus offers logfile name among options
6044b5c is described below

commit 6044b5c2fd83632eb1441545cb1d427a74e98b0a
Author: MS <ms@taler.net>
AuthorDate: Wed Jun 24 11:52:08 2020 +0200

    nexus offers logfile name among options
---
 nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt    |  9 +++++++--
 .../main/resources/{logback.xml => late-logback.xml} |  7 ++++---
 util/src/main/kotlin/Config.kt                       | 20 ++++++++++++++++++++
 3 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index f2b9419..9896243 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -28,14 +28,15 @@ import com.github.ajalt.clikt.parameters.arguments.argument
 import com.github.ajalt.clikt.parameters.options.default
 import com.github.ajalt.clikt.parameters.options.option
 import com.github.ajalt.clikt.parameters.options.prompt
-import com.github.ajalt.clikt.parameters.types.int
 import org.jetbrains.exposed.sql.transactions.transaction
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
 import tech.libeufin.nexus.server.serverMain
 import tech.libeufin.util.CryptoUtil.hashpw
+import setLogFile
 
-val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus")
+
+lateinit var logger: Logger
 
 class NexusCommand : CliktCommand() {
     override fun run() = Unit
@@ -47,13 +48,17 @@ class Serve : CliktCommand("Run nexus HTTP server") {
             helpFormatter = CliktHelpFormatter(showDefaultValues = true)
         }
     }
+    private val logFile by option()
     private val dbName by option().default("libeufin-nexus.sqlite3")
     private val host by option().default("127.0.0.1")
     override fun run() {
+        setLogFile(logFile, "nexusLogFile","late-logback.xml")
+        logger = LoggerFactory.getLogger("tech.libeufin.nexus")
         serverMain(dbName, host)
     }
 }
 
+
 class Superuser : CliktCommand("Add superuser or change pw") {
     private val dbName by option().default("libeufin-nexus.sqlite3")
     private val username by argument()
diff --git a/nexus/src/main/resources/logback.xml 
b/nexus/src/main/resources/late-logback.xml
similarity index 80%
rename from nexus/src/main/resources/logback.xml
rename to nexus/src/main/resources/late-logback.xml
index 2d6c01f..cd545cb 100644
--- a/nexus/src/main/resources/logback.xml
+++ b/nexus/src/main/resources/late-logback.xml
@@ -1,13 +1,14 @@
-<configuration>
+<!-- configuration scan="true" -->
+<configuration scan="true">
     <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
         <encoder>
             <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - 
%msg%n</pattern>
         </encoder>
     </appender>
 
-
+    <property name="NEXUS_LOG_FILE" value="${nexusLogFile}" />
     <appender name="NEXUS-FILE" class="ch.qos.logback.core.FileAppender">
-        <file>/tmp/nexus.log</file>
+        <file>${NEXUS_LOG_FILE}</file>
         <append>true</append>
         <encoder>
             <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - 
%msg%n</pattern>
diff --git a/util/src/main/kotlin/Config.kt b/util/src/main/kotlin/Config.kt
new file mode 100644
index 0000000..62f3b27
--- /dev/null
+++ b/util/src/main/kotlin/Config.kt
@@ -0,0 +1,20 @@
+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

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]