libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 530c8b9394abff9023d2885736003b886a5f5714
parent 7884146d6e3a159ee9bf2b0eec2b09210c1ce75e
Author: tanhengyeow <E0032242@u.nus.edu>
Date:   Wed, 24 Jun 2020 20:21:54 +0800

Merge branch 'master' of ssh://git.taler.net/libeufin

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 9+++++++--
Anexus/src/main/resources/late-logback.xml | 29+++++++++++++++++++++++++++++
Dnexus/src/main/resources/logback.xml | 28----------------------------
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 6+++++-
Asandbox/src/main/resources/late-logback.xml | 37+++++++++++++++++++++++++++++++++++++
Dsandbox/src/main/resources/logback.xml | 36------------------------------------
Autil/src/main/kotlin/Config.kt | 23+++++++++++++++++++++++
7 files changed, 101 insertions(+), 67 deletions(-)

diff --git 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/late-logback.xml b/nexus/src/main/resources/late-logback.xml @@ -0,0 +1,28 @@ +<!-- 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>${NEXUS_LOG_FILE}</file> + <append>true</append> + <encoder> + <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> + </encoder> + </appender> + + <logger name="tech.libeufin" level="TRACE"/> + <logger name="io.netty" level="WARN"/> + <logger name="ktor" level="WARN"/> + <logger name="Exposed" level="WARN"/> + + <root level="WARN"> + <appender-ref ref="STDOUT"/> + <appender-ref ref="NEXUS-FILE"/> + </root> + +</configuration> +\ No newline at end of file diff --git a/nexus/src/main/resources/logback.xml b/nexus/src/main/resources/logback.xml @@ -1,27 +0,0 @@ -<configuration> - <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> - - - <appender name="NEXUS-FILE" class="ch.qos.logback.core.FileAppender"> - <file>/tmp/nexus.log</file> - <append>true</append> - <encoder> - <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> - </encoder> - </appender> - - <logger name="tech.libeufin" level="TRACE"/> - <logger name="io.netty" level="WARN"/> - <logger name="ktor" level="WARN"/> - <logger name="Exposed" level="WARN"/> - - <root level="WARN"> - <appender-ref ref="STDOUT"/> - <appender-ref ref="NEXUS-FILE"/> - </root> - -</configuration> -\ No newline at end of file diff --git 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/late-logback.xml b/sandbox/src/main/resources/late-logback.xml @@ -0,0 +1,36 @@ +<configuration> + <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="SANDBOX_LOG_FILE" value="${sandboxLogFile}" /> + <appender name="SANDBOX-FILE" class="ch.qos.logback.core.FileAppender"> + <file>${SANDBOX_LOG_FILE}</file> + <append>false</append> + <encoder> + <pattern>%-5relative %-5level %logger{35} - %msg%n</pattern> + </encoder> + </appender> + + <logger name="tech.libeufin.sandbox" level="DEBUG" additivity="false"> + <appender-ref ref="STDOUT" /> + <appender-ref ref="SANDBOX-FILE" /> + </logger> + + <logger name="tech.libeufin.util" level="TRACE" additivity="false"> + <appender-ref ref="STDOUT" /> + <appender-ref ref="SANDBOX-FILE" /> + </logger> + + + <logger name="io.netty" level="WARN" /> + <logger name="ktor" level="WARN" /> + <logger name="Exposed" level="WARN" /> + + <root level="WARN"> + <appender-ref ref="STDOUT" /> + </root> + +</configuration> +\ No newline at end of file diff --git a/sandbox/src/main/resources/logback.xml b/sandbox/src/main/resources/logback.xml @@ -1,35 +0,0 @@ -<configuration> - <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> - - <appender name="SANDBOX-FILE" class="ch.qos.logback.core.FileAppender"> - <file>/tmp/sandbox.log</file> - <append>false</append> - <encoder> - <pattern>%-5relative %-5level %logger{35} - %msg%n</pattern> - </encoder> - </appender> - - <logger name="tech.libeufin.sandbox" level="DEBUG" additivity="false"> - <appender-ref ref="STDOUT" /> - <appender-ref ref="SANDBOX-FILE" /> - </logger> - - <logger name="tech.libeufin.util" level="TRACE" additivity="false"> - <appender-ref ref="STDOUT" /> - <appender-ref ref="SANDBOX-FILE" /> - </logger> - - - <logger name="io.netty" level="WARN" /> - <logger name="ktor" level="WARN" /> - <logger name="Exposed" level="WARN" /> - - <root level="WARN"> - <appender-ref ref="STDOUT" /> - </root> - -</configuration> -\ No newline at end of file diff --git a/util/src/main/kotlin/Config.kt 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