Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ group = "com.mindera.lodge"
version = "1.0.0"

kotlin {
jvmToolchain(8)
jvmToolchain(11)
androidTarget()
jvm()
iosX64()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ class LogcatAppender(
} else {
val chunks = ceil((1f * length / maxLineLength).toDouble()).toInt()
for (i in 1..chunks) {
val start = maxLineLength * (i - 1)
val max = maxLineLength * i
if (max < length) {
it.add("[Chunk $i of $chunks] " + substring(maxLineLength * (i - 1), max))
} else {
it.add("[Chunk $i of $chunks] " + substring(maxLineLength * (i - 1)))
}
it.add(if (max < length) substring(start, max) else substring(start))
}
Comment thread
tiper marked this conversation as resolved.
}
}
Expand Down
21 changes: 4 additions & 17 deletions src/appleMain/kotlin/com/mindera/lodge/appenders/OSAppender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.mindera.lodge.LOG.SEVERITY.FATAL
import com.mindera.lodge.LOG.SEVERITY.INFO
import com.mindera.lodge.LOG.SEVERITY.VERBOSE
import com.mindera.lodge.LOG.SEVERITY.WARN
import com.mindera.lodge.extensions.emoji
import com.mindera.lodge.extensions.initial
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.ptr
import platform.darwin.OS_LOG_DEFAULT
Expand Down Expand Up @@ -41,10 +43,7 @@ class OSAppender(
override fun log(severity: SEVERITY, tag: String, t: Throwable?, log: String) {
with(severity.toLevel()) {
val prefix = severity.prefix(tag)
log(prefix + log)
t?.let {
log(prefix + it.stackTraceToString())
}
log(t?.let { "$prefix$log\n" + it.stackTraceToString() } ?: (prefix + log))
}
Comment thread
tiper marked this conversation as resolved.
}

Expand All @@ -61,17 +60,5 @@ class OSAppender(
ERROR -> OS_LOG_TYPE_ERROR
FATAL -> OS_LOG_TYPE_ERROR
}

private fun SEVERITY.prefix(tag: String) = "$emoji $name: $tag"

// Kudos to Napier https://github.com/AAkira/Napier#darwinios-macos-watchos-tvosintelapple-silicon
private val SEVERITY.emoji: String get()= when (this) {
VERBOSE -> "⚪"
DEBUG -> "🔵"
INFO -> "🟢"
WARN -> "🟡"
ERROR -> "🔴"
FATAL -> "🟤"
}

private fun SEVERITY.prefix(tag: String) = "$emoji | $initial | $tag: "
}
Loading