Deciding upfront if message ever has to be pretty printed. Avoids pretty printing it multiple times

This commit is contained in:
dankito 2024-08-23 13:06:48 +02:00
parent c0796cfc38
commit 4f3924f2cd
1 changed files with 9 additions and 4 deletions

View File

@ -43,7 +43,7 @@ open class MessageLogCollector(
val message = if (logEntry.type == MessageLogEntryType.Error) { val message = if (logEntry.type == MessageLogEntryType.Error) {
logEntry.message + (if (logEntry.error != null) NewLine + getStackTrace(logEntry.error!!) else "") logEntry.message + (if (logEntry.error != null) NewLine + getStackTrace(logEntry.error!!) else "")
} else { } else {
prettyPrintFinTsMessage(logEntry.message) logEntry.message
} }
return if (options.removeSensitiveDataFromMessageLog) { return if (options.removeSensitiveDataFromMessageLog) {
@ -57,9 +57,15 @@ open class MessageLogCollector(
open fun addMessageLog(type: MessageLogEntryType, message: String, context: MessageContext) { open fun addMessageLog(type: MessageLogEntryType, message: String, context: MessageContext) {
val messageTrace = createMessageTraceString(type, context) 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) { open fun logError(loggingClass: KClass<*>, message: String, context: MessageContext, e: Exception? = null) {
@ -80,7 +86,6 @@ open class MessageLogCollector(
} }
if (options.fireCallbackOnMessageLogs) { if (options.fireCallbackOnMessageLogs) {
// TODO: pretty print message
callback.messageLogAdded(newEntry) callback.messageLogAdded(newEntry)
} }
} }