OSLogStore: How does Predicate work?

Originator:steipete
Number:rdar://FB8518539 Date Originated:
Status:Open Resolved:
Product:iOS/macOS Product Version:
Classification: Reproducible:
 
With following sample code to access OSLogStore:

func getLogEntries() -> Result<[OSLogEntryLog], Error> {
    var logMessages: [OSLogEntryLog] = []
    do {
        // FB8269189: OSLogStore does not work iOS
        let logStore = try OSLogStore(scope: .currentProcessIdentifier)
        let oneHourAgo = logStore.position(date: Date().addingTimeInterval(-3600))


        // TODO: How to format the predicate? See "PREDICATE-BASED FILTERING" in `man log`.
        // Things I tried unsuccessfully:
        // - NSPredicate(format: "subsystem == %@", "com.steipete.LoggingTest")
        // - NSPredicate(format: "subsystem == \"com.steipete.LoggingTest\"")

        // FB8518476: The Swift shims for for the entries enumerator are missing.
        let allEntries = try Array(logStore.__entriesEnumerator(position: oneHourAgo, predicate: nil))
        let osLogEntryLogObjects = allEntries.compactMap { $0 as? OSLogEntryLog }
        for entry in osLogEntryLogObjects where entry.subsystem == subsystem {
            logMessages.append(entry)
        }
        return .success(logMessages)
    } catch {
        print("Error: \(error)")
        return .failure(error)
    }
}

I was unable to write a predicate to filter the log messages. Manual filtering works. Please provide sample code or fix the predicate logic - above syntax is what I would expect to work.

Thanks!

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!