gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: moving loglevel setter to util


From: gnunet
Subject: [libeufin] branch master updated: moving loglevel setter to util
Date: Wed, 24 Jun 2020 18:56:05 +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 6faffd2  moving loglevel setter to util
6faffd2 is described below

commit 6faffd2ad236a7f3b30971fe7cba382b0d075744
Author: MS <ms@taler.net>
AuthorDate: Wed Jun 24 18:55:32 2020 +0200

    moving loglevel setter to util
---
 nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 11 ++++++-----
 util/src/main/kotlin/Config.kt                    | 21 +++++++++++++++++++++
 2 files changed, 27 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 bcf0859..a5b7ac5 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -33,10 +33,11 @@ import org.slf4j.Logger
 import org.slf4j.LoggerFactory
 import tech.libeufin.nexus.server.serverMain
 import tech.libeufin.util.CryptoUtil.hashpw
-import tech.libeufin.util.*
+import ch.qos.logback.classic.Level
+import ch.qos.logback.classic.LoggerContext
+import tech.libeufin.util.setLogLevel
 
-
-lateinit var logger: Logger
+val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus")
 
 class NexusCommand : CliktCommand() {
     override fun run() = Unit
@@ -50,13 +51,13 @@ class Serve : CliktCommand("Run nexus HTTP server") {
     }
     private val dbName by option().default("libeufin-nexus.sqlite3")
     private val host by option().default("127.0.0.1")
+    private val logLevel by option()
     override fun run() {
-        logger = LoggerFactory.getLogger("tech.libeufin.nexus")
+        setLogLevel(logLevel)
         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/util/src/main/kotlin/Config.kt b/util/src/main/kotlin/Config.kt
index 8631086..607ac67 100644
--- a/util/src/main/kotlin/Config.kt
+++ b/util/src/main/kotlin/Config.kt
@@ -1,7 +1,10 @@
 package tech.libeufin.util
 
+import ch.qos.logback.classic.Level
+import ch.qos.logback.classic.LoggerContext
 import ch.qos.logback.classic.util.ContextInitializer
 import ch.qos.logback.core.util.Loader
+import org.slf4j.LoggerFactory
 
 /**
  * Set system properties to wanted values, and load logback configuration 
after.
@@ -19,4 +22,22 @@ fun setLogFile(logFile: String?, logFileNameAsProperty: 
String, configFileName:
         println("Warning: could not find log config file")
     }
     System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, 
configFilePath.toString())
+}
+
+/**
+ * Set level of any logger belonging to LibEuFin (= has "libeufin" in name)
+ * _and_ found under the calling classpath (= obeying to the same logback.xml)
+ */
+fun setLogLevel(logLevel: String?) {
+    when (val immutable = logLevel) {
+        is String -> {
+            val ctx = LoggerFactory.getILoggerFactory() as LoggerContext
+            val loggers: List<ch.qos.logback.classic.Logger> = ctx.loggerList
+            loggers.forEach {
+                if (it.name.contains("libeufin")) {
+                    it.level = Level.toLevel(immutable)
+                }
+            }
+        }
+    }
 }
\ 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]