-
-
Save erikng/4b47aad70c6a07a72d5a641251971c3f to your computer and use it in GitHub Desktop.
Sample code to access OSLogStore on iOS and macOS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let subsystem = "com.steipete.LoggingTest" | |
func getLogEntries() throws -> [OSLogEntryLog] { | |
// FB8269189: OSLogStore does not work iOS. | |
let logStore = try OSLogStore(scope: .currentProcessIdentifier) | |
let oneHourAgo = logStore.position(date: Date().addingTimeInterval(-3600)) | |
#if os(macOS) | |
let allEntries = try logStore.getEntries(at: oneHourAgo) | |
#else | |
// FB8518476: The Swift shims for for the entries enumerator are missing. | |
let allEntries = try Array(logStore.__entriesEnumerator(position: oneHourAgo, predicate: nil)) | |
#endif | |
// FB8518539: Using NSPredicate to filter the subsystem doesn't seem to work. | |
return allEntries | |
.compactMap { $0 as? OSLogEntryLog } | |
.filter { $0.subsystem == subsystem } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment