diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/log/MessageLogCollector.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/log/MessageLogCollector.kt index 600518b6..a01268d2 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/log/MessageLogCollector.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/log/MessageLogCollector.kt @@ -37,23 +37,25 @@ open class MessageLogCollector( // in either case remove sensitive data after response is parsed as otherwise some information like account holder name and accounts may is not set yet on BankData open val messageLog: List - // safe CPU cycles by only formatting and removing sensitive data if messageLog is really requested - get() = _messageLog.map { MessageLogEntry(it.type, it.context, it.messageTrace, createMessageForLog(it), it.error, it.parsedSegments, it.time) } + // safe CPU cycles by only removing sensitive data if messageLog is really requested + get() = _messageLog.map { + val message = createMessageForLog(it) + val messageWithoutSensitiveData = if (options.removeSensitiveDataFromMessageLog) { + safelyRemoveSensitiveDataFromMessage(message, it.context.bank) + } else { + message + } - private fun createMessageForLog(logEntry: MessageLogEntry): String { - val message = if (logEntry.type == MessageLogEntryType.Error) { + MessageLogEntry(it.type, it.context, it.messageTrace, message, messageWithoutSensitiveData, it.error, it.parsedSegments, it.time) + } + + private fun createMessageForLog(logEntry: MessageLogEntry): String = + if (logEntry.type == MessageLogEntryType.Error) { logEntry.message + (if (logEntry.error != null) NewLine + getStackTrace(logEntry.error!!) else "") } else { logEntry.message } - return if (options.removeSensitiveDataFromMessageLog) { - safelyRemoveSensitiveDataFromMessage(message, logEntry.context.bank) - } else { - message - } - } - open fun addMessageLog(type: MessageLogEntryType, message: String, context: MessageContext, parsedSegments: List = emptyList()) { val messageTrace = createMessageTraceString(type, context) @@ -76,7 +78,7 @@ open class MessageLogCollector( protected open fun addMessageLogEntry(type: MessageLogEntryType, context: MessageContext, messageTrace: String, message: String, error: Throwable? = null, parsedSegments: List = emptyList()) { if (options.collectMessageLog || options.fireCallbackOnMessageLogs) { - val newEntry = MessageLogEntry(type, context, messageTrace, message, error, parsedSegments) + val newEntry = MessageLogEntry(type, context, messageTrace, message, null, error, parsedSegments) if (options.collectMessageLog) { _messageLog.add(newEntry) diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/MessageLogEntry.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/MessageLogEntry.kt index c2a9c8b6..c9210744 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/MessageLogEntry.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/MessageLogEntry.kt @@ -11,6 +11,7 @@ open class MessageLogEntry( open val context: MessageContext, open val messageTrace: String, open val message: String, + open val messageWithoutSensitiveData: String? = null, open val error: Throwable? = null, /** * Parsed received segments.