Kermit icon indicating copy to clipboard operation
Kermit copied to clipboard

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

Open ggajews opened this issue 1 year ago • 0 comments

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
        )
    }
}

ggajews avatar Jun 20 '24 13:06 ggajews