From 20fe60d9f6bfb4a57607f13aba83abda3ea74509 Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 15 Oct 2024 02:00:23 +0200 Subject: [PATCH] Also pretty printing error messages --- .../banking/fints/log/MessageLogCollector.kt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) 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 34130747..600518b6 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 @@ -57,12 +57,7 @@ open class MessageLogCollector( open fun addMessageLog(type: MessageLogEntryType, message: String, context: MessageContext, parsedSegments: List = emptyList()) { val messageTrace = createMessageTraceString(type, context) - - val prettyPrintMessage = if (options.collectMessageLog || options.fireCallbackOnMessageLogs || log.isDebugEnabled) { // only use CPU cycles if message will ever be used / displayed - prettyPrintFinTsMessage(message) - } else { - message - } + val prettyPrintMessage = prettyPrintMessageIfRequired(message) log.debug { "$messageTrace\n$prettyPrintMessage" } @@ -72,10 +67,11 @@ open class MessageLogCollector( open fun logError(loggingClass: KClass<*>, message: String, context: MessageContext, e: Throwable? = null) { val type = MessageLogEntryType.Error val messageTrace = createMessageTraceString(type, context) + val prettyPrintMessage = prettyPrintFinTsMessage(message) // error messages almost always get logged / displayed -> pretty print - LoggerFactory.getLogger(loggingClass).error(e) { messageTrace + message } + LoggerFactory.getLogger(loggingClass).error(e) { "$messageTrace\n$prettyPrintMessage" } - addMessageLogEntry(type, context, messageTrace, message, e) + addMessageLogEntry(type, context, messageTrace, prettyPrintMessage, e) } protected open fun addMessageLogEntry(type: MessageLogEntryType, context: MessageContext, messageTrace: String, message: String, error: Throwable? = null, parsedSegments: List = emptyList()) { @@ -113,6 +109,13 @@ open class MessageLogCollector( } } + protected open fun prettyPrintMessageIfRequired(message: String): String = + if (options.collectMessageLog || options.fireCallbackOnMessageLogs || log.isDebugEnabled) { // only use CPU cycles if message will ever be used / displayed + prettyPrintFinTsMessage(message) + } else { + message + } + protected open fun prettyPrintFinTsMessage(message: String): String = finTsUtils.prettyPrintFinTsMessage(message)