From f5e13da668a1c216da34521eee59ac974a8a2cbc Mon Sep 17 00:00:00 2001 From: Josiah Glosson Date: Tue, 5 Dec 2023 16:20:56 -0600 Subject: [PATCH] Log marker and stacktrace on Darwin --- .../io/github/oshai/kotlinlogging/DarwinKLogger.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/DarwinKLogger.kt b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/DarwinKLogger.kt index 59e89aaa..3490d190 100644 --- a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/DarwinKLogger.kt +++ b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/DarwinKLogger.kt @@ -17,7 +17,18 @@ public class DarwinKLogger(override val name: String, override val underlyingLog override fun at(level: Level, marker: Marker?, block: KLoggingEventBuilder.() -> Unit) { if (isLoggingEnabledFor(level, marker)) { KLoggingEventBuilder().apply(block).run { - _os_log_internal(__dso_handle.ptr, underlyingLogger, level.toDarwinLevel(), message) + val formattedMessage = buildString { + marker?.getName()?.let { + append(it) + append(" ") + } + append(message) + cause?.stackTraceToString()?.let { + append('\n') + append(it) + } + } + _os_log_internal(__dso_handle.ptr, underlyingLogger, level.toDarwinLevel(), formattedMessage) } } }