Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSLogStore does not produce logs written to console by platformLogWriter on iOS #339

Closed
kirillzh opened this issue Mar 14, 2023 · 6 comments

Comments

@kirillzh
Copy link

kirillzh commented Mar 14, 2023

https://developer.apple.com/documentation/oslog/oslogstore

@kpgalligan
Copy link
Collaborator

It looks like that's for reading, not writing: https://steipete.com/posts/logging-in-swift/. Unless I'm reading that wrong.

@kirillzh
Copy link
Author

Ah that's right, it's for reading only. The problem that I ran into is that platformLogWriter() didn't seem to write iOS console logs in a way where they would end up in the OSLogStore. Haven't tested with Kermit 2.0 yet though!

@kirillzh kirillzh changed the title Add LogWriter for iOS OSLogStore OSLogStore doesn't seem to produce logs written to console by platformLogWriter on iOS Mar 15, 2023
robbiehanson added a commit to robbiehanson/Kermit that referenced this issue Oct 16, 2023
robbiehanson added a commit to robbiehanson/Kermit that referenced this issue Oct 16, 2023
@robbiehanson
Copy link
Contributor

This bug is still present as of Kermit v2.0.2. And it's a critical bug.

If the OSLogWriter is functioning properly, the log entries will be visible/available in the following locations:

  • Xcode's debug console
  • Console.app
  • OSLogStore API

The first 2 are working fine currently, but the last isn't.

The OSLogStore is an API for reading log entries that have been sent to OSLog system. For example, your application might want to export a log file, and send it to the development team for debugging. To do this, you MUST call the OSLogStore API within your code. If you do this now, with the current codebase, all log entries sent from Kermit result in a log message of <compose failure [UUID]>.

Unfortunately this renders Kermit unsuitable for use with many iOS applications, because it means:

  • any log entries sent thru Kermit are LOST
  • any kotlin-multiplatform libary that uses Kermit won't have readable log entries

To be clear: Kermit works fine if you're debugging on your own device when plugged into Xcode. But if you need to debug problems from actual users of your app, then you MUST use OSLogStore, and Kermit has unfortunately broken all log entries within OSLogStore.

@kirillzh kirillzh changed the title OSLogStore doesn't seem to produce logs written to console by platformLogWriter on iOS OSLogStore does not produce logs written to console by platformLogWriter on iOS Nov 16, 2023
@marcodallaba
Copy link

marcodallaba commented Nov 17, 2023

Totally agree with @robbiehanson .
My current solution is to create a LogWriter in the app and pass it as a parameter to the kmm library.

final class MyLogger: LogWriter {
    private static let subsystem = Bundle.main.bundleIdentifier ?? "app_system"
    private let myLogger = Logger(subsystem: subsystem, category: "MyLogger")
    
    override func log(severity: Severity, message: String, tag: String, throwable: KotlinThrowable?) {
        #if APP_ENV_PROD
        myLogger("\(Date()) [MYLOGGER] [\(severity)] \(message, privacy: .private)")
        #else
        myLogger.debug("\(Date()) [MYLOGGER] [\(severity)] \(message, privacy: .public)")
        #endif
    }
}

@rocketraman
Copy link
Contributor

Any updates on this? It is frustrating to not be able to see logs on a device without Xcode attached.

KevinSchildhorn added a commit that referenced this issue Nov 6, 2024
* Replacing usage of private API with public API, by switching to cInterop. Fixes issue #339

* Update build.gradle.kts

---------

Co-authored-by: Kevin Schildhorn <kevin.schildhorn@gmail.com>
@KevinSchildhorn
Copy link
Contributor

The relative PR has been merged in. It should be available in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants