OSLogStore:getEntries(with:at:matching:) missing from iOS?

Hello Apple,

I might be wrong but it seems like getEntries(with:at:matching:) is missing from iOS? Else please tell me how I should the get log entries on iOS 😃

Please see the documentation at https://developer.apple.com/documentation/oslog/oslogstore/3204125-getentries

Regards,

Jens

Answered by slzh in 679222022

This seems to be in fact working in Beta 1 in the simulator and on device: see the sample below. Despite being marked as NS_REFINED_FOR_SWIFT you need to call this as described in https://developer.apple.com/documentation/swift/objective-c_and_c_code_customization/improving_objective-c_api_declarations_for_swift

@main

struct LogReaderApp: App {

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }

    init() {
        do {
            os_log("Test message! \(UInt(42), format: .hex)")
            let store = try OSLogStore.init(scope: .currentProcessIdentifier)
            let position = store.position(date: Date().addingTimeInterval(-3600))
            let enumerator = try store.__entriesEnumerator(options: [.reverse], position: position, predicate: nil)
            enumerator.forEach { element in
                var message = element as? OSLogEntry
                dump(message.debugDescription)
                dump(message?.composedMessage)
            }
        } catch {
            dump(error)
        }
    }
}

This is a known issue (r. 56157644). I can’t make any promises as to when it’ll be fixed but, as always, I recommend that you test with any future beta releases as they are seeded.

In the meantime, you can work around this by bouncing over to Objective-C.

Oh, and other than this, how’s OSLog working out for you? This has been a long time coming |-: and I haven’t yet had a chance to test the iOS support for myself.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

as I don't hope we'll have a re-run of

The best way to avoid that would be to test it now and file bugs if you have problems. The fact that Swift is misbehaving doesn’t stop you from testing it in Objective-C and, as long as it works from Objective-C, getting it working from Swift is just a small matter of code (-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

This seems to be in fact working in Beta 1 in the simulator and on device: see the sample below. Despite being marked as NS_REFINED_FOR_SWIFT you need to call this as described in https://developer.apple.com/documentation/swift/objective-c_and_c_code_customization/improving_objective-c_api_declarations_for_swift

@main

struct LogReaderApp: App {

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }

    init() {
        do {
            os_log("Test message! \(UInt(42), format: .hex)")
            let store = try OSLogStore.init(scope: .currentProcessIdentifier)
            let position = store.position(date: Date().addingTimeInterval(-3600))
            let enumerator = try store.__entriesEnumerator(options: [.reverse], position: position, predicate: nil)
            enumerator.forEach { element in
                var message = element as? OSLogEntry
                dump(message.debugDescription)
                dump(message?.composedMessage)
            }
        } catch {
            dump(error)
        }
    }
}
OSLogStore:getEntries(with:at:matching:) missing from iOS?
 
 
Q