From c0796cfc382e1031f9daadc1e0ff833edd23ed04 Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 23 Aug 2024 13:02:10 +0200 Subject: [PATCH] Added option to disable collection messageLog --- .../banking/fints/config/FinTsClientOptions.kt | 9 +++++++++ .../banking/fints/log/MessageLogCollector.kt | 14 +++++++++----- .../fints/response/client/FinTsClientResponse.kt | 4 ++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/config/FinTsClientOptions.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/config/FinTsClientOptions.kt index b37330a1..0aaddc2f 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/config/FinTsClientOptions.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/config/FinTsClientOptions.kt @@ -3,6 +3,15 @@ package net.dankito.banking.fints.config import net.dankito.banking.fints.model.ProductData data class FinTsClientOptions( + + /** + * If FinTS messages sent to and received from bank servers and errors should be collected. They are then accessible + * via [net.dankito.banking.fints.response.client.FinTsClientResponse.messageLog]. + * + * Set to false by default. + */ + val collectMessageLog: Boolean = false, + /** * If set to true then [net.dankito.banking.fints.callback.FinTsClientCallback.messageLogAdded] get fired when a * FinTS message get sent to bank server, a FinTS message is received from bank server or an error occurred. diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/MessageLogCollector.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/MessageLogCollector.kt index 564e2972..3295acb9 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/MessageLogCollector.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/MessageLogCollector.kt @@ -72,13 +72,17 @@ open class MessageLogCollector( } protected open fun addMessageLogEntry(type: MessageLogEntryType, context: MessageContext, messageTrace: String, message: String, error: Throwable? = null) { - val newEntry = MessageLogEntry(type, context, messageTrace, message, error) + if (options.collectMessageLog || options.fireCallbackOnMessageLogs) { + val newEntry = MessageLogEntry(type, context, messageTrace, message, error) - _messageLog.add(newEntry) + if (options.collectMessageLog) { + _messageLog.add(newEntry) + } - if (options.fireCallbackOnMessageLogs) { - // TODO: pretty print message - callback.messageLogAdded(newEntry) + if (options.fireCallbackOnMessageLogs) { + // TODO: pretty print message + callback.messageLogAdded(newEntry) + } } } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/FinTsClientResponse.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/FinTsClientResponse.kt index 3b53d669..2aad2c60 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/FinTsClientResponse.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/FinTsClientResponse.kt @@ -18,6 +18,10 @@ open class FinTsClientResponse( open val isStrongAuthenticationRequired: Boolean, open val tanRequired: TanResponse? = null, + /** + * Collected FinTS messages sent to and received from bank servers and error messages. Will only be available if + * [net.dankito.banking.fints.config.FinTsClientOptions.collectMessageLog] is set to true (is disabled by default). + */ open val messageLog: List, /**