touchlab / Kermit

Kermit by Touchlab is a Kotlin Multiplatform centralized logging utility.
https://kermit.touchlab.co
Apache License 2.0
699 stars 40 forks source link

OSLogWriter logs doesn't show up in console after process is detached from XCode #400

Open ggajews opened 2 months ago

ggajews commented 2 months ago

I couldn't find any logs in console after my process is detached from Xcode (after app kill and restart). I found similar thread here: https://forums.developer.apple.com/forums/thread/727380 The source of this issue might be hidden in this part:

When running without Xcode, it will output Hello Cruel to the Console. I'd have to add Hello Cruel (planet, privacy: .public) for the full message to appear.

I assume, when using os_log with format specifiers (%s) and CvarArg, it treats the whole message as private, and that's why it's not outputting anything when run without Xcode.

I did a quick check and changing the DarwinLoggerActual implementation to always log public messages seems to solve this issue:

private object FixedDarwinLoggerActual : DarwinLogger {
    @OptIn(ExperimentalForeignApi::class)
    override fun log(osLogSeverity: UByte, message: String) {
        _os_log_internal(
            __dso_handle.ptr,
            OS_LOG_DEFAULT,
            osLogSeverity,
            "%{public}s",
            message
        )
    }
}