Implemented that on Android whole message gets logged (LogCat at maximum prints 4076 bytes per message)

This commit is contained in:
dankito 2020-12-06 21:06:03 +01:00
parent eac1d1da40
commit 8b7e1f7020
1 changed files with 20 additions and 2 deletions

View File

@ -1,7 +1,16 @@
package net.dankito.utils.multiplatform.log
import net.dankito.utils.multiplatform.os.OsHelper
open class Slf4jLogger(protected val slf4jLogger: org.slf4j.Logger, protected val osHelper: OsHelper = OsHelper()) : Logger {
companion object {
const val MaxLogCatMessageLength = 4 * 1024
}
open class Slf4jLogger(protected val slf4jLogger: org.slf4j.Logger) : Logger {
override val name: String
get() = slf4jLogger.name
@ -87,7 +96,16 @@ open class Slf4jLogger(protected val slf4jLogger: org.slf4j.Logger) : Logger {
val args = determineArguments(exception, arguments)
logOnLevel(message, args)
if (osHelper.isRunningOnAndroid && message.length > MaxLogCatMessageLength) {
var index = 0
// as LogCat only prints at maximum 4076 bytes per message, break up message in multiple strings
message.chunked(MaxLogCatMessageLength - 5).forEach { chunk -> // -5 to also log index
logOnLevel("[${index++}] $chunk", args)
}
}
else {
logOnLevel(message, args)
}
}
protected open fun determineArguments(exception: Throwable?, arguments: Array<out Any>): Array<out Any> {