diff options
author | Antoine A <> | 2024-01-19 14:06:42 +0000 |
---|---|---|
committer | Antoine A <> | 2024-01-19 14:06:42 +0000 |
commit | 413621478175372689d69553ca5b036ddfdbd0ac (patch) | |
tree | 96319ff2146d727c6a65c2765976e326837bce28 | |
parent | 30e44180c9a64dabaad519e8c5a949929ae28493 (diff) | |
download | libeufin-413621478175372689d69553ca5b036ddfdbd0ac.tar.gz libeufin-413621478175372689d69553ca5b036ddfdbd0ac.tar.bz2 libeufin-413621478175372689d69553ca5b036ddfdbd0ac.zip |
Improve log format and add log level cli flag
29 files changed, 78 insertions, 140 deletions
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Config.kt b/bank/src/main/kotlin/tech/libeufin/bank/Config.kt index c3f7db94..4604ad04 100644 --- a/bank/src/main/kotlin/tech/libeufin/bank/Config.kt +++ b/bank/src/main/kotlin/tech/libeufin/bank/Config.kt @@ -23,12 +23,8 @@ import TalerConfig import TalerConfigError import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json -import org.slf4j.Logger -import org.slf4j.LoggerFactory import tech.libeufin.util.DatabaseConfig -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.bank.Config") - /** * Application the parsed configuration. */ diff --git a/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt b/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt index eb39c136..04616e88 100644 --- a/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt +++ b/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt @@ -47,7 +47,7 @@ import tech.libeufin.bank.db.TransactionDAO.* import tech.libeufin.bank.db.WithdrawalDAO.* import tech.libeufin.util.* -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.bank.accountsMgmtHandlers") +private val logger: Logger = LoggerFactory.getLogger("libeufin-bank-api") fun Routing.coreBankApi(db: Database, ctx: BankConfig) { get("/config") { diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt index 9f543c48..89eac6d2 100644 --- a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt +++ b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt @@ -16,7 +16,6 @@ * License along with LibEuFin; see the file COPYING. If not, see * <http://www.gnu.org/licenses/> */ -// Main HTTP handlers and related data definitions. package tech.libeufin.bank @@ -58,7 +57,7 @@ import tech.libeufin.bank.db.AccountDAO.* import tech.libeufin.bank.db.* import tech.libeufin.util.* -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.bank.Main") +private val logger: Logger = LoggerFactory.getLogger("libeufin-bank") // Dirty local variable to stop the server in test TODO remove this ugly hack var engine: ApplicationEngine? = null @@ -108,7 +107,7 @@ val bodyPlugin = createApplicationPlugin("BodyLimitAndDecompression") { */ fun Application.corebankWebApp(db: Database, ctx: BankConfig) { install(CallLogging) { - this.level = Level.DEBUG + this.level = Level.INFO this.logger = tech.libeufin.bank.logger this.format { call -> val status = call.response.status() @@ -218,17 +217,6 @@ fun Application.corebankWebApp(db: Database, ctx: BankConfig) { } } -class CommonOption: OptionGroup() { - val config by option( - "--config", "-c", - help = "Specifies the configuration file" - ).path( - mustExist = true, - canBeDir = false, - mustBeReadable = true, - ).convert { it.toString() } // TODO take path to load config -} - class BankDbInit : CliktCommand("Initialize the libeufin-bank database", name = "dbinit") { private val common by CommonOption() private val requestReset by option( @@ -236,7 +224,7 @@ class BankDbInit : CliktCommand("Initialize the libeufin-bank database", name = help = "Reset database (DANGEROUS: All existing data is lost)" ).flag() - override fun run() = cliCmd(logger){ + override fun run() = cliCmd(logger, common.log) { val config = talerConfig(common.config) val cfg = config.loadDbConfig() val ctx = config.loadBankConfig(); @@ -266,7 +254,7 @@ class BankDbInit : CliktCommand("Initialize the libeufin-bank database", name = class ServeBank : CliktCommand("Run libeufin-bank HTTP server", name = "serve") { private val common by CommonOption() - override fun run() = cliCmd(logger) { + override fun run() = cliCmd(logger, common.log) { val cfg = talerConfig(common.config) val ctx = cfg.loadBankConfig() val dbCfg = cfg.loadDbConfig() @@ -332,7 +320,7 @@ class ChangePw : CliktCommand("Change account password", name = "passwd") { help = "Account password used for authentication" ) - override fun run() = cliCmd(logger) { + override fun run() = cliCmd(logger, common.log) { val cfg = talerConfig(common.config) val ctx = cfg.loadBankConfig() val dbCfg = cfg.loadDbConfig() @@ -378,7 +366,7 @@ class EditAccount : CliktCommand( private val cashout_payto_uri: IbanPayTo? by option(help = "Payto URI of a fiant account who receive cashout amount").convert { IbanPayTo(it) } private val debit_threshold: TalerAmount? by option(help = "Max debit allowed for this account").convert { TalerAmount(it) } - override fun run() = cliCmd(logger) { + override fun run() = cliCmd(logger, common.log) { val cfg = talerConfig(common.config) val ctx = cfg.loadBankConfig() val dbCfg = cfg.loadDbConfig() @@ -456,7 +444,7 @@ class CreateAccount : CliktCommand( private val json by argument().convert { Json.decodeFromString<RegisterAccountRequest>(it) }.optional() private val options by CreateAccountOption().cooccurring() - override fun run() = cliCmd(logger) { + override fun run() = cliCmd(logger, common.log) { // TODO support setting tan val cfg = talerConfig(common.config) val ctx = cfg.loadBankConfig() diff --git a/bank/src/main/kotlin/tech/libeufin/bank/TalerCommon.kt b/bank/src/main/kotlin/tech/libeufin/bank/TalerCommon.kt index 5f8830cb..fa135161 100644 --- a/bank/src/main/kotlin/tech/libeufin/bank/TalerCommon.kt +++ b/bank/src/main/kotlin/tech/libeufin/bank/TalerCommon.kt @@ -35,10 +35,6 @@ import kotlinx.serialization.json.* import net.taler.common.errorcodes.TalerErrorCode import net.taler.wallet.crypto.Base32Crockford import net.taler.wallet.crypto.EncodingException -import org.slf4j.Logger -import org.slf4j.LoggerFactory - -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.bank.TalerCommon") /** 32-byte Crockford's Base32 encoded data */ @Serializable(with = Base32Crockford32B.Serializer::class) diff --git a/bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApi.kt b/bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApi.kt index 4da9a3ab..6e832703 100644 --- a/bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApi.kt +++ b/bank/src/main/kotlin/tech/libeufin/bank/WireGatewayApi.kt @@ -29,19 +29,17 @@ import io.ktor.server.routing.* import io.ktor.util.pipeline.PipelineContext import java.time.Instant import net.taler.common.errorcodes.TalerErrorCode -import org.slf4j.Logger -import org.slf4j.LoggerFactory import tech.libeufin.bank.db.* import tech.libeufin.bank.db.ExchangeDAO.* import tech.libeufin.bank.auth.* -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus") fun Routing.wireGatewayApi(db: Database, ctx: BankConfig) { get("/taler-wire-gateway/config") { call.respond(TWGConfigResponse( currency = ctx.regionalCurrency )) + return@get } auth(db, TokenScope.readwrite) { diff --git a/bank/src/main/kotlin/tech/libeufin/bank/auth/auth.kt b/bank/src/main/kotlin/tech/libeufin/bank/auth/auth.kt index edb8e305..1a3add97 100644 --- a/bank/src/main/kotlin/tech/libeufin/bank/auth/auth.kt +++ b/bank/src/main/kotlin/tech/libeufin/bank/auth/auth.kt @@ -27,15 +27,11 @@ import io.ktor.util.pipeline.PipelineContext import java.time.Instant import net.taler.common.errorcodes.TalerErrorCode import net.taler.wallet.crypto.Base32Crockford -import org.slf4j.Logger -import org.slf4j.LoggerFactory import tech.libeufin.bank.db.AccountDAO.* import tech.libeufin.bank.db.* import tech.libeufin.bank.* import tech.libeufin.util.* -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.bank.Authentication") - /** Used to store if the currenly authenticated user is admin */ private val AUTH_IS_ADMIN = AttributeKey<Boolean>("is_admin"); /** Used to store used auth token */ diff --git a/bank/src/main/kotlin/tech/libeufin/bank/db/Database.kt b/bank/src/main/kotlin/tech/libeufin/bank/db/Database.kt index e4effe00..6f692fd0 100644 --- a/bank/src/main/kotlin/tech/libeufin/bank/db/Database.kt +++ b/bank/src/main/kotlin/tech/libeufin/bank/db/Database.kt @@ -38,7 +38,7 @@ import io.ktor.http.HttpStatusCode import net.taler.common.errorcodes.TalerErrorCode import tech.libeufin.bank.* -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.bank.Database") +private val logger: Logger = LoggerFactory.getLogger("libeufin-bank-db") /** * This error occurs in case the timestamp took by the bank for some diff --git a/bank/src/main/kotlin/tech/libeufin/bank/db/NotificationWatcher.kt b/bank/src/main/kotlin/tech/libeufin/bank/db/NotificationWatcher.kt index c96a1e5d..c17ffb58 100644 --- a/bank/src/main/kotlin/tech/libeufin/bank/db/NotificationWatcher.kt +++ b/bank/src/main/kotlin/tech/libeufin/bank/db/NotificationWatcher.kt @@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory import tech.libeufin.util.* import tech.libeufin.bank.* -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.util.NotificationWatcher") +private val logger: Logger = LoggerFactory.getLogger("libeufin-bank-db-watcher") /** Postgres notification collector and distributor */ internal class NotificationWatcher(private val pgSource: PGSimpleDataSource) { @@ -103,7 +103,7 @@ internal class NotificationWatcher(private val pgSource: PGSimpleDataSource) { } } } catch (e: Exception) { - logger.warn("notification_watcher failed: $e") + logger.warn("$e") delay(backoff.next()) } } diff --git a/bank/src/main/kotlin/tech/libeufin/bank/db/TransactionDAO.kt b/bank/src/main/kotlin/tech/libeufin/bank/db/TransactionDAO.kt index a72f9743..9c21fd53 100644 --- a/bank/src/main/kotlin/tech/libeufin/bank/db/TransactionDAO.kt +++ b/bank/src/main/kotlin/tech/libeufin/bank/db/TransactionDAO.kt @@ -26,7 +26,7 @@ import java.time.* import java.sql.Types import tech.libeufin.bank.* -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.util.TransactionDAO") +private val logger: Logger = LoggerFactory.getLogger("libeufin-bank-tx-dao") /** Data access logic for transactions */ class TransactionDAO(private val db: Database) { diff --git a/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt b/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt index 84dc96a6..47de2b15 100644 --- a/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt +++ b/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt @@ -37,15 +37,11 @@ import java.time.* import java.time.temporal.* import java.util.* import net.taler.common.errorcodes.TalerErrorCode -import org.slf4j.Logger -import org.slf4j.LoggerFactory import tech.libeufin.util.* import tech.libeufin.bank.db.* import tech.libeufin.bank.db.AccountDAO.* import tech.libeufin.bank.auth.* -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.bank.helpers") - fun ApplicationCall.expectParameter(name: String) = parameters[name] ?: throw badRequest( "Missing '$name' param", diff --git a/bank/src/main/resources/logback.xml b/bank/src/main/resources/logback.xml index 271c094c..342ce4b0 100644 --- a/bank/src/main/resources/logback.xml +++ b/bank/src/main/resources/logback.xml @@ -1,27 +1,16 @@ <configuration> <appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender"> - <target>System.err</target> + <target>System.err</target> <encoder> - <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> + <pattern>%d{dd-MMM-yyyy'T'HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> - <logger name="tech.libeufin.bank" level="ALL" additivity="false"> - <appender-ref ref="STDERR" /> - </logger> - <logger name="tech.libeufin.util" level="ALL" additivity="false"> - <appender-ref ref="STDERR" /> - </logger> - <logger name="tech.libeufin.nexus" level="ALL" additivity="false"> - <appender-ref ref="STDERR" /> - </logger> + <logger name="io.netty" level="WARN" /> + <logger name="ktor" level="WARN" /> + <logger name="com.zaxxer.hikari" level="OFF" /> - <logger name="io.netty" level="INFO" /> - <logger name="ktor" level="TRACE" /> - <logger name="Exposed" level="INFO" /> - - <root level="WARN"> + <root level="DEBUG"> <appender-ref ref="STDERR" /> </root> - -</configuration> +</configuration>
\ No newline at end of file diff --git a/integration/src/main/kotlin/Main.kt b/integration/src/main/kotlin/Main.kt index 0dcd4259..1eaa6f28 100644 --- a/integration/src/main/kotlin/Main.kt +++ b/integration/src/main/kotlin/Main.kt @@ -80,6 +80,8 @@ class Cli : CliktCommand("Run integration tests on banks provider") { runBlocking { Path("test/$name").createDirectories() val conf = "conf/$name.conf" + val log = "DEBUG" + val flags = " -c $conf -L $log" val cfg = loadConfig(conf) val clientKeysPath = Path(cfg.requireString("nexus-ebics", "client_private_keys_file")) @@ -88,8 +90,8 @@ class Cli : CliktCommand("Run integration tests on banks provider") { var hasClientKeys = clientKeysPath.exists() var hasBankKeys = bankKeysPath.exists() - if (ask("Reset DB ? y/n>") == "y") nexusCmd.test("dbinit -r -c $conf").assertOk() - else nexusCmd.test("dbinit -c $conf").assertOk() + if (ask("Reset DB ? y/n>") == "y") nexusCmd.test("dbinit -r $flags").assertOk() + else nexusCmd.test("dbinit $flags").assertOk() val nexusDb = NexusDb("postgresql:///libeufincheck") when (kind) { @@ -106,27 +108,27 @@ class Cli : CliktCommand("Run integration tests on banks provider") { if (!hasClientKeys) { step("Test INI order") ask("Got to https://isotest.postfinance.ch/corporates/user/settings/ebics and click on 'Reset EBICS user'.\nPress Enter when done>") - nexusCmd.test("ebics-setup -c $conf") + nexusCmd.test("ebics-setup $flags") .assertErr("ebics-setup should failed the first time") } if (!hasBankKeys) { step("Test HIA order") ask("Got to https://isotest.postfinance.ch/corporates/user/settings/ebics and click on 'Activate EBICS user'.\nPress Enter when done>") - nexusCmd.test("ebics-setup --auto-accept-keys -c $conf") + nexusCmd.test("ebics-setup --auto-accept-keys $flags") .assertOk("ebics-setup should succeed the second time") } val payto = "payto://iban/CH2989144971918294289?receiver-name=Test" step("Test fetch transactions") - nexusCmd.test("ebics-fetch --transient -c $conf --pinned-start 2022-01-01").assertOk() + nexusCmd.test("ebics-fetch --transient $flags --pinned-start 2022-01-01").assertOk() while (true) { when (ask("Run 'fetch', 'submit', 'tx', 'txs', 'logs', 'ack' or 'exit'>")) { "fetch" -> { step("Fetch new transactions") - nexusCmd.test("ebics-fetch --transient -c $conf").assertOk() + nexusCmd.test("ebics-fetch --transient $flags").assertOk() } "tx" -> { step("Test submit one transaction") @@ -137,7 +139,7 @@ class Cli : CliktCommand("Run integration tests on banks provider") { initiationTime = Instant.now(), requestUid = Base32Crockford.encode(randBytes(16)) )) - nexusCmd.test("ebics-submit --transient -c $conf").assertOk() + nexusCmd.test("ebics-submit --transient $flags").assertOk() } "txs" -> { step("Test submit many transaction") @@ -150,19 +152,19 @@ class Cli : CliktCommand("Run integration tests on banks provider") { requestUid = Base32Crockford.encode(randBytes(16)) )) } - nexusCmd.test("ebics-submit --transient -c $conf").assertOk() + nexusCmd.test("ebics-submit --transient $flags").assertOk() } "submit" -> { step("Submit pending transactions") - nexusCmd.test("ebics-submit --transient -c $conf").assertOk() + nexusCmd.test("ebics-submit --transient $flags").assertOk() } "logs" -> { step("Fetch logs") - nexusCmd.test("ebics-fetch --transient -c $conf --only-logs").assertOk() + nexusCmd.test("ebics-fetch --transient $flags --only-logs").assertOk() } "ack" -> { step("Fetch ack") - nexusCmd.test("ebics-fetch --transient -c $conf --only-ack").assertOk() + nexusCmd.test("ebics-fetch --transient $flags --only-ack").assertOk() } "exit" -> break } @@ -174,11 +176,11 @@ class Cli : CliktCommand("Run integration tests on banks provider") { if (!hasBankKeys) { step("Test HIA order") - nexusCmd.test("ebics-setup --auto-accept-keys -c $conf").assertOk("ebics-setup should succeed the second time") + nexusCmd.test("ebics-setup --auto-accept-keys $flags").assertOk("ebics-setup should succeed the second time") } step("Test fetch transactions") - nexusCmd.test("ebics-fetch --transient -c $conf --pinned-start 2022-01-01").assertOk() + nexusCmd.test("ebics-fetch --transient $flags --pinned-start 2022-01-01").assertOk() while (true) { when (ask("Run 'fetch', 'submit', 'logs', 'ack' or 'exit'>")) { @@ -200,15 +202,15 @@ class Cli : CliktCommand("Run integration tests on banks provider") { initiationTime = Instant.now(), requestUid = Base32Crockford.encode(randBytes(16)) )) - nexusCmd.test("ebics-submit --transient -c $conf").assertOk() + nexusCmd.test("ebics-submit --transient $flags").assertOk() } "logs" -> { step("Fetch logs") - nexusCmd.test("ebics-fetch --transient -c $conf --only-logs").assertOk() + nexusCmd.test("ebics-fetch --transient $flags --only-logs").assertOk() } "ack" -> { step("Fetch ack") - nexusCmd.test("ebics-fetch --transient -c $conf --only-ack").assertOk() + nexusCmd.test("ebics-fetch --transient $flags --only-ack").assertOk() } "exit" -> break } diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DbInit.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DbInit.kt index 906943df..19b90cdd 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/DbInit.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/DbInit.kt @@ -17,7 +17,7 @@ class DbInit : CliktCommand("Initialize the libeufin-nexus database", name = "db help = "Reset database (DANGEROUS: All existing data is lost)" ).flag() - override fun run() { + override fun run() = cliCmd(logger, common.log) { val cfg = loadConfig(common.config).dbConfig() pgDataSource(cfg.dbConnStr).pgConnection().use { conn -> if (requestReset) { diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt index 05952d21..4545c54f 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt @@ -498,7 +498,7 @@ class EbicsFetch: CliktCommand("Fetches bank records. Defaults to camt.054 noti * mode when no flags are passed to the invocation. * FIXME: reduce code duplication with the submit subcommand. */ - override fun run() = cliCmd(logger) { + override fun run() = cliCmd(logger, common.log) { val cfg: EbicsSetupConfig = extractEbicsConfig(common.config) val dbCfg = cfg.config.dbConfig() diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt index 40a09d7f..bb8b788a 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt @@ -285,7 +285,7 @@ class EbicsSetup: CliktCommand("Set up the EBICS subscriber") { /** * This function collects the main steps of setting up an EBICS access. */ - override fun run() = cliCmd(logger) { + override fun run() = cliCmd(logger, common.log) { val cfg = extractEbicsConfig(common.config) if (checkFullConfig) { cfg.config.requireString("nexus-submit", "frequency").apply { diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt index 1e691099..2a694e97 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt @@ -266,7 +266,7 @@ class EbicsSubmit : CliktCommand("Submits any initiated payment found in the dat * or long-polls (currently not implemented) for new payments. * FIXME: reduce code duplication with the fetch subcommand. */ - override fun run() = cliCmd(logger) { + override fun run() = cliCmd(logger, common.log) { val cfg: EbicsSetupConfig = extractEbicsConfig(common.config) val dbCfg = cfg.config.dbConfig() val (clientKeys, bankKeys) = expectFullKeys(cfg) diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt index 3a535aff..3854879e 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -51,7 +51,7 @@ import java.security.interfaces.RSAPublicKey import java.io.FileNotFoundException val NEXUS_CONFIG_SOURCE = ConfigSource("libeufin", "libeufin-nexus", "libeufin-nexus") -val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus") +val logger: Logger = LoggerFactory.getLogger("libeufin-nexus") val myJson = Json { this.serializersModule = SerializersModule { contextual(RSAPrivateCrtKey::class) { RSAPrivateCrtKeySerializer } diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics2.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics2.kt index e1ef647d..5bcc2480 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics2.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics2.kt @@ -39,7 +39,7 @@ import java.time.ZoneId import java.util.* import javax.xml.datatype.DatatypeFactory -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus.Ebics2") +private val logger: Logger = LoggerFactory.getLogger("libeufin-nexus-ebics2") /** * Convenience function to download via EBICS with a diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsCommon.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsCommon.kt index b700abb2..963a9ec7 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsCommon.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsCommon.kt @@ -56,8 +56,6 @@ import java.time.format.DateTimeFormatter import java.util.* import java.util.zip.DeflaterInputStream -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus.EbicsCommon") - /** * Available EBICS versions. */ @@ -100,7 +98,7 @@ enum class SupportedDocument { */ fun ByteArray.unzipForEach(lambda: (String, String) -> Unit) { if (this.isEmpty()) { - tech.libeufin.nexus.logger.warn("Empty archive") + logger.warn("Empty archive") return } val mem = SeekableInMemoryByteChannel(this) @@ -163,7 +161,7 @@ suspend fun HttpClient.postToBank(bankUrl: String, msg: String): String? { } catch (e: Exception) { // hard error (network issue, invalid URL, ..) - tech.libeufin.nexus.logger.error("Could not POST to bank at: $bankUrl, detail: ${e.message}") + logger.error("Could not POST to bank at: $bankUrl, detail: ${e.message}") return null } // Bank was found, but the EBICS request wasn't served. @@ -171,7 +169,7 @@ suspend fun HttpClient.postToBank(bankUrl: String, msg: String): String? { // _should_ not be related to EBICS. 404 for a wrong URL // is one example. if (resp.status != HttpStatusCode.OK) { - tech.libeufin.nexus.logger.error("Bank was found at $bankUrl, but EBICS wasn't served. Response status: ${resp.status}, body: ${resp.bodyAsText()}") + logger.error("Bank was found at $bankUrl, but EBICS wasn't served. Response status: ${resp.status}, body: ${resp.bodyAsText()}") return null } return resp.bodyAsText() diff --git a/nexus/src/main/resources/logback.xml b/nexus/src/main/resources/logback.xml index b18b437e..342ce4b0 100644 --- a/nexus/src/main/resources/logback.xml +++ b/nexus/src/main/resources/logback.xml @@ -1,23 +1,16 @@ -<!-- configuration scan="true" --> <configuration> <appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender"> - <target>System.err</target> + <target>System.err</target> <encoder> - <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> + <pattern>%d{dd-MMM-yyyy'T'HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> - <logger name="tech.libeufin.nexus" level="ALL" additivity="false"> - <appender-ref ref="STDERR" /> - </logger> - - <logger name="io.netty" level="WARN"/> - <logger name="ktor" level="WARN"/> - <logger name="Exposed" level="WARN"/> - <logger name="tech.libeufin.util" level="DEBUG"/> + <logger name="io.netty" level="WARN" /> + <logger name="ktor" level="WARN" /> + <logger name="com.zaxxer.hikari" level="OFF" /> - <root level="WARN"> - <appender-ref ref="STDERR"/> + <root level="DEBUG"> + <appender-ref ref="STDERR" /> </root> - -</configuration> +</configuration>
\ No newline at end of file diff --git a/util/src/main/kotlin/Cli.kt b/util/src/main/kotlin/Cli.kt index 93a15a21..0c1803f5 100644 --- a/util/src/main/kotlin/Cli.kt +++ b/util/src/main/kotlin/Cli.kt @@ -29,10 +29,15 @@ import com.github.ajalt.clikt.parameters.options.* import com.github.ajalt.clikt.parameters.groups.* import org.slf4j.Logger import org.slf4j.LoggerFactory +import org.slf4j.event.Level -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.util.ConfigCli") +private val logger: Logger = LoggerFactory.getLogger("libeufin-config") -fun cliCmd(logger: Logger, lambda: () -> Unit) { +fun cliCmd(logger: Logger, level: Level, lambda: () -> Unit) { + // Set root log level + val root = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME) as ch.qos.logback.classic.Logger + root.setLevel(ch.qos.logback.classic.Level.convertAnSLF4JLevel(level)); + // Run cli command catching all errors try { lambda() } catch (e: Throwable) { @@ -44,6 +49,7 @@ fun cliCmd(logger: Logger, lambda: () -> Unit) { cause = cause.cause } logger.error(msg.toString()) + logger.debug("$e", e) throw ProgramResult(1) } } @@ -63,6 +69,10 @@ class CommonOption: OptionGroup() { canBeDir = false, mustBeReadable = true, ).convert { it.toString() } // TODO take path to load config + val log by option( + "--log", "-L", + help = "Configure logging to use LOGLEVEL" + ).enum<Level>().default(Level.INFO) } class CliConfigCmd(configSource: ConfigSource) : CliktCommand("Inspect or change the configuration", name = "config") { @@ -83,7 +93,7 @@ private class CliConfigGet(private val configSource: ConfigSource) : CliktComman private val optionName by argument() - override fun run() = cliCmd(logger) { + override fun run() = cliCmd(logger, common.log) { val config = talerConfig(configSource, common.config) if (isPath) { val res = config.lookupPath(sectionName, optionName) @@ -107,7 +117,7 @@ private class CliConfigPathsub(private val configSource: ConfigSource) : CliktCo private val common by CommonOption() private val pathExpr by argument() - override fun run() = cliCmd(logger) { + override fun run() = cliCmd(logger, common.log) { val config = talerConfig(configSource, common.config) println(config.pathsub(pathExpr)) } @@ -116,7 +126,7 @@ private class CliConfigPathsub(private val configSource: ConfigSource) : CliktCo private class CliConfigDump(private val configSource: ConfigSource) : CliktCommand("Dump the configuration", name = "dump") { private val common by CommonOption() - override fun run() = cliCmd(logger) { + override fun run() = cliCmd(logger, common.log) { val config = talerConfig(configSource, common.config) println("# install path: ${config.getInstallPath()}") println(config.stringify()) diff --git a/util/src/main/kotlin/DB.kt b/util/src/main/kotlin/DB.kt index 0fa26c9a..facff98b 100644 --- a/util/src/main/kotlin/DB.kt +++ b/util/src/main/kotlin/DB.kt @@ -32,7 +32,7 @@ import java.sql.SQLException fun getCurrentUser(): String = System.getProperty("user.name") -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.util.DB") +private val logger: Logger = LoggerFactory.getLogger("libeufin-db") // Check GANA (https://docs.gnunet.org/gana/index.html) for numbers allowance. diff --git a/util/src/main/kotlin/HTTP.kt b/util/src/main/kotlin/HTTP.kt index cedd07b6..bc314c6f 100644 --- a/util/src/main/kotlin/HTTP.kt +++ b/util/src/main/kotlin/HTTP.kt @@ -7,7 +7,7 @@ import io.ktor.server.util.* import org.slf4j.Logger import org.slf4j.LoggerFactory -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.util.HTTP") +private val logger: Logger = LoggerFactory.getLogger("libeufin-common") // Get the base URL of a request, returns null if any problem occurs. fun ApplicationRequest.getBaseUrl(): String? { diff --git a/util/src/main/kotlin/IbanPayto.kt b/util/src/main/kotlin/IbanPayto.kt index 8920aed9..b190f58a 100644 --- a/util/src/main/kotlin/IbanPayto.kt +++ b/util/src/main/kotlin/IbanPayto.kt @@ -5,7 +5,7 @@ import org.slf4j.LoggerFactory import java.net.URI import java.net.URLDecoder -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.util.IbanPayto") +private val logger: Logger = LoggerFactory.getLogger("libeufin-common") // Payto information. data class IbanPayto( diff --git a/util/src/main/kotlin/TalerConfig.kt b/util/src/main/kotlin/TalerConfig.kt index acbdefc7..b9435d19 100644 --- a/util/src/main/kotlin/TalerConfig.kt +++ b/util/src/main/kotlin/TalerConfig.kt @@ -25,7 +25,7 @@ import kotlin.io.path.Path import kotlin.io.path.isReadable import kotlin.io.path.listDirectoryEntries -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.util.TalerConfig") +private val logger: Logger = LoggerFactory.getLogger("libeufin-config") private data class Section( val entries: MutableMap<String, String>, diff --git a/util/src/main/kotlin/XMLUtil.kt b/util/src/main/kotlin/XMLUtil.kt index 67ab77dc..66e7b9b1 100644 --- a/util/src/main/kotlin/XMLUtil.kt +++ b/util/src/main/kotlin/XMLUtil.kt @@ -62,7 +62,7 @@ import javax.xml.xpath.XPath import javax.xml.xpath.XPathConstants import javax.xml.xpath.XPathFactory -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.util.XMLUtil") +private val logger: Logger = LoggerFactory.getLogger("libeufin-xml") class DefaultNamespaces : NamespacePrefixMapper() { override fun getPreferredPrefix(namespaceUri: String?, suggestion: String?, requirePrefix: Boolean): String? { diff --git a/util/src/main/kotlin/time.kt b/util/src/main/kotlin/time.kt index 25f5265f..ce0ef745 100644 --- a/util/src/main/kotlin/time.kt +++ b/util/src/main/kotlin/time.kt @@ -25,7 +25,7 @@ import java.time.* import java.time.format.DateTimeFormatter import java.time.temporal.ChronoUnit -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.util.time") +private val logger: Logger = LoggerFactory.getLogger("libeufin-common") /** * Converts the 'this' Instant to the number of nanoseconds diff --git a/util/src/test/kotlin/XmlUtilTest.kt b/util/src/test/kotlin/XmlUtilTest.kt index 32b91a23..d0b003fb 100644 --- a/util/src/test/kotlin/XmlUtilTest.kt +++ b/util/src/test/kotlin/XmlUtilTest.kt @@ -14,9 +14,6 @@ import java.util.* import javax.xml.transform.stream.StreamSource import tech.libeufin.util.XMLUtil.Companion.signEbicsResponse -private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.util.XmlUnitTest") - - class XmlUtilTest { @Test @@ -68,7 +65,7 @@ class XmlUtilTest { </HTDResponseOrderData>""".trimIndent() ) - logger.debug(tmp.value.partnerInfo.orderInfoList[0].description) + println(tmp.value.partnerInfo.orderInfoList[0].description) } @Test @@ -77,7 +74,7 @@ class XmlUtilTest { XMLUtil.convertStringToJaxb<EbicsKeyManagementResponse>("<malformed xml>") } catch (e: javax.xml.bind.UnmarshalException) { // just ensuring this is the exception - logger.info("caught") + println("caught") return } assertTrue(false) diff --git a/util/src/test/resources/logback.xml b/util/src/test/resources/logback.xml deleted file mode 100644 index 4e7740ac..00000000 --- a/util/src/test/resources/logback.xml +++ /dev/null @@ -1,21 +0,0 @@ -<configuration> - <appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender"> - <target>System.err</target> - <encoder> - <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> - </encoder> - </appender> - - <logger name="tech.libeufin.util" level="DEBUG" additivity="false"> - <appender-ref ref="STDERR" /> - </logger> - - <logger name="io.netty" level="WARN" /> - <logger name="ktor" level="WARN" /> - <logger name="Exposed" level="WARN" /> - - <root level="WARN"> - <appender-ref ref="STDERR" /> - </root> - -</configuration>
\ No newline at end of file |