Open KevinnZou opened 1 year ago
Which version of Kermit? How is your Kermit configured? What log writer(s) are you using?
I am using version 2.0.0-RC5. I tried it in several ways but all failed.
Logger.d { "" }
Logger.setMinSeverity(Severity.Debug)
Logger.d { "" }
internal object KLogger : Logger(
config = loggerConfigInit(
platformLogWriter(DefaultFormatter),
minSeverity = Severity.Debug
),
tag = "ComposeWebView"
)
All three ways do not work and it will only print out the logs with Logger.i or higher severity. They work fine on Android and Desktop platforms
@kpgalligan Are there any updates?
@kpgalligan You can directly test this project https://github.com/KevinnZou/compose-webview-multiplatform. Logger.d works well on Android and Desktop but fails on iOS.
I added this:
fun MainViewController() = ComposeUIViewController {
Logger.v { "Verbose" }
Logger.d { "Debug" }
Logger.i { "Info" }
Logger.w { "Warn" }
Logger.e { "Error" }
WebViewApp()
}
This was printed in the Xcode log:
⚪️ Verbose
🔵 Debug
🟢 Info
🟡 Warn
🔴 Error
If you're not seeing this, then I'm guessing you have a min log set in Xcode?
Added my changes https://github.com/kpgalligan/compose-webview-multiplatform
@kpgalligan Thanks for your reply! I am wondering did you test the log in Android Studio? Since we can directly run iosApp in Android Studio and see logs in the console, we don't need to open Xcode at all.
I never run iOS apps from Android Studio :) Hmm.
I've looked at it in AS. I can't find any config to set the level that is logged there. I assume the KMM plugin for AS is not showing everything for whatever reason. By that I mean they've made a decision to not show OS_LOG_TYPE_DEBUG
statements in the log for whatever reason.
I will need to think about how to make some kind of config for the Apple-side log writer to allow you to override how that log writer works by default. We can't (AFAIK) detect if you're in AS, Xcode, or nothing. I also don't really want to force all verbose and debug statements to output at OS_LOG_TYPE_INFO
solely because of the KMM AS plugin.
So, maybe there's a way to pass a param to platformLogWriter
, but that's a pretty specific param for a global helper. Maybe just OSLogWriter/XcodeSeverityWriter
, but then the out-of-the-box experience isn't ideal.
Anyway, for reference, here's the code mapping log levels:
private fun kermitSeverityToOsLogType(severity: Severity): UByte = when (severity) {
Severity.Verbose, Severity.Debug -> OS_LOG_TYPE_DEBUG
Severity.Info -> OS_LOG_TYPE_INFO
Severity.Warn -> OS_LOG_TYPE_DEFAULT
Severity.Error -> OS_LOG_TYPE_ERROR
Severity.Assert -> OS_LOG_TYPE_FAULT
}
If I'd known about this earlier I would've at least made that open
and not private
, so writing a custom version would involve minimal code.
I think this needs to have a bug filed for the KMM Plugin for AS, as it is dropping log statements. You should be able to select your own filter there, similar to Logcat's view
@kpgalligan Thank you for your reply! I truly appreciate your investigation. I also attempted to run the app in Xcode and was able to see all the logs. Therefore, as you mentioned, the issue lies with the KMM Plugin for AS. I will open an issue with them. Thank you once again for your help!
same issue with AppCode but not Xcode AppCode show below
2024-03-10 22:35:21.140636+0800 Mint[29800:899637] 🟢 info
2024-03-10 22:35:21.140694+0800 Mint[29800:899637] 🟡 warning
2024-03-10 22:35:21.140731+0800 Mint[29800:899637] 🔴 error
Xcode shows below
🔵 debug
🟢 info
🟡 warning
🔴 error
Logger.d does not print logs on iOS platforms even if I set minSeverity to Debug.