Extracted determining arguments

This commit is contained in:
dankito 2020-12-06 20:41:24 +01:00
parent 87e272565f
commit d38f7b224b
1 changed files with 12 additions and 8 deletions

View File

@ -85,19 +85,23 @@ open class Slf4jLogger(protected val slf4jLogger: org.slf4j.Logger) : Logger {
val message = messageCreator()
if (exception != null) {
if (arguments.isEmpty()) {
logOnLevel(message, arrayOf(exception))
val args = determineArguments(exception, arguments)
logOnLevel(message, args)
}
else {
protected open fun determineArguments(exception: Throwable?, arguments: Array<out Any>): Array<out Any> {
return if (exception != null) {
if (arguments.isEmpty()) {
arrayOf(exception)
} else {
val argumentsIncludingException: MutableList<Any> = mutableListOf(exception)
argumentsIncludingException.addAll(0, arguments.toList())
logOnLevel(message, argumentsIncludingException.toTypedArray())
argumentsIncludingException.toTypedArray()
}
}
else {
logOnLevel(message, arguments)
} else {
arguments
}
}