From 4f3924f2cd6fdb8a27e0d39b32d7cb34f5c5b409 Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 23 Aug 2024 13:06:48 +0200 Subject: [PATCH] Deciding upfront if message ever has to be pretty printed. Avoids pretty printing it multiple times --- .../banking/fints/log/MessageLogCollector.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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 3295acb9..4a364b89 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 @@ -43,7 +43,7 @@ open class MessageLogCollector( val message = if (logEntry.type == MessageLogEntryType.Error) { logEntry.message + (if (logEntry.error != null) NewLine + getStackTrace(logEntry.error!!) else "") } else { - prettyPrintFinTsMessage(logEntry.message) + logEntry.message } return if (options.removeSensitiveDataFromMessageLog) { @@ -57,9 +57,15 @@ open class MessageLogCollector( open fun addMessageLog(type: MessageLogEntryType, message: String, context: MessageContext) { val messageTrace = createMessageTraceString(type, context) - log.debug { "$messageTrace\n${prettyPrintFinTsMessage(message)}" } + val prettyPrintMessage = if (options.collectMessageLog || options.fireCallbackOnMessageLogs || log.isDebugEnabled) { // only use CPU cycles if message will ever be used / displayed + prettyPrintFinTsMessage(message) + } else { + message + } - addMessageLogEntry(type, context, messageTrace, message) + log.debug { "$messageTrace\n$prettyPrintMessage" } + + addMessageLogEntry(type, context, messageTrace, prettyPrintMessage) } open fun logError(loggingClass: KClass<*>, message: String, context: MessageContext, e: Exception? = null) { @@ -80,7 +86,6 @@ open class MessageLogCollector( } if (options.fireCallbackOnMessageLogs) { - // TODO: pretty print message callback.messageLogAdded(newEntry) } }