From d38f7b224bd7b768e9c34b0031eb07d882eabe94 Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 6 Dec 2020 20:41:24 +0100 Subject: [PATCH] Extracted determining arguments --- .../utils/multiplatform/log/Slf4jLogger.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/log/Slf4jLogger.kt b/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/log/Slf4jLogger.kt index 55e0f291..64f197bd 100644 --- a/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/log/Slf4jLogger.kt +++ b/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/log/Slf4jLogger.kt @@ -85,19 +85,23 @@ open class Slf4jLogger(protected val slf4jLogger: org.slf4j.Logger) : Logger { val message = messageCreator() - if (exception != null) { + val args = determineArguments(exception, arguments) + + logOnLevel(message, args) + } + + protected open fun determineArguments(exception: Throwable?, arguments: Array): Array { + return if (exception != null) { if (arguments.isEmpty()) { - logOnLevel(message, arrayOf(exception)) - } - else { + arrayOf(exception) + } else { val argumentsIncludingException: MutableList = mutableListOf(exception) argumentsIncludingException.addAll(0, arguments.toList()) - logOnLevel(message, argumentsIncludingException.toTypedArray()) + argumentsIncludingException.toTypedArray() } - } - else { - logOnLevel(message, arguments) + } else { + arguments } }