diff options
author | tanhengyeow <E0032242@u.nus.edu> | 2020-06-24 20:21:54 +0800 |
---|---|---|
committer | tanhengyeow <E0032242@u.nus.edu> | 2020-06-24 20:21:54 +0800 |
commit | 530c8b9394abff9023d2885736003b886a5f5714 (patch) | |
tree | d918fb211f1431205cb2ce9870da9a57b86ebca0 | |
parent | 7884146d6e3a159ee9bf2b0eec2b09210c1ce75e (diff) | |
parent | 3c50e816038d0efa289329f286cb81ac31fbbeee (diff) | |
download | libeufin-530c8b9394abff9023d2885736003b886a5f5714.tar.gz libeufin-530c8b9394abff9023d2885736003b886a5f5714.tar.bz2 libeufin-530c8b9394abff9023d2885736003b886a5f5714.zip |
Merge branch 'master' of ssh://git.taler.net/libeufin
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 9 | ||||
-rw-r--r-- | nexus/src/main/resources/late-logback.xml (renamed from nexus/src/main/resources/logback.xml) | 7 | ||||
-rw-r--r-- | sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 6 | ||||
-rw-r--r-- | sandbox/src/main/resources/late-logback.xml (renamed from sandbox/src/main/resources/logback.xml) | 3 | ||||
-rw-r--r-- | util/src/main/kotlin/Config.kt | 22 |
5 files changed, 40 insertions, 7 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt index f2b9419b..f3510d5e 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 tech.libeufin.util.* -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 index 2d6c01ff..cd545cbe 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/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt index 8f77187b..d88f010e 100644 --- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt +++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -64,13 +64,14 @@ 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 tech.libeufin.util.* class CustomerNotFound(id: String?) : Exception("Customer ${id} not found") class BadInputData(inputData: String?) : Exception("Customer provided invalid input data: ${inputData}") class UnacceptableFractional(badNumber: BigDecimal) : Exception( "Unacceptable fractional part ${badNumber}" ) -val LOGGER: Logger = LoggerFactory.getLogger("tech.libeufin.sandbox") +lateinit var LOGGER: Logger data class SandboxError( val statusCode: HttpStatusCode, @@ -83,7 +84,10 @@ class SandboxCommand : CliktCommand() { class Serve : CliktCommand("Run sandbox HTTP server") { private val dbName by option().default("libeufin-sandbox.sqlite3") + private val logFile by option() override fun run() { + setLogFile(logFile, "sandboxLogFile", "late-logback.xml") + LOGGER = LoggerFactory.getLogger("tech.libeufin.sandbox") serverMain(dbName) } } diff --git a/sandbox/src/main/resources/logback.xml b/sandbox/src/main/resources/late-logback.xml index 7df7bcc7..ddff9197 100644 --- a/sandbox/src/main/resources/logback.xml +++ b/sandbox/src/main/resources/late-logback.xml @@ -5,8 +5,9 @@ </encoder> </appender> + <property name="SANDBOX_LOG_FILE" value="${sandboxLogFile}" /> <appender name="SANDBOX-FILE" class="ch.qos.logback.core.FileAppender"> - <file>/tmp/sandbox.log</file> + <file>${SANDBOX_LOG_FILE}</file> <append>false</append> <encoder> <pattern>%-5relative %-5level %logger{35} - %msg%n</pattern> 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 |