From d13df905a8c427b4ad37c305f8c155669abfab80 Mon Sep 17 00:00:00 2001 From: Josiah Glosson Date: Mon, 15 Jan 2024 03:08:08 -0600 Subject: [PATCH] Log marker and stacktrace on Darwin (#379) --- .../oshai/kotlinlogging/DarwinKLogger.kt | 18 +++++++++++++++++- 1 file changed, 17 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 24a5bb78..ddee780c 100644 --- a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/DarwinKLogger.kt +++ b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/DarwinKLogger.kt @@ -20,7 +20,23 @@ 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 + ) } } }