Implemented that on Android whole message gets logged (LogCat at maximum prints 4076 bytes per message)
This commit is contained in:
parent
eac1d1da40
commit
8b7e1f7020
|
@ -1,7 +1,16 @@
|
||||||
package net.dankito.utils.multiplatform.log
|
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
|
override val name: String
|
||||||
get() = slf4jLogger.name
|
get() = slf4jLogger.name
|
||||||
|
@ -87,8 +96,17 @@ open class Slf4jLogger(protected val slf4jLogger: org.slf4j.Logger) : Logger {
|
||||||
|
|
||||||
val args = determineArguments(exception, arguments)
|
val args = determineArguments(exception, arguments)
|
||||||
|
|
||||||
|
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)
|
logOnLevel(message, args)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected open fun determineArguments(exception: Throwable?, arguments: Array<out Any>): Array<out Any> {
|
protected open fun determineArguments(exception: Throwable?, arguments: Array<out Any>): Array<out Any> {
|
||||||
return if (exception != null) {
|
return if (exception != null) {
|
||||||
|
|
Loading…
Reference in New Issue