Created
August 24, 2020 10:35
-
-
Save steipete/89ebcc27048b5378af5cfe778c542c2e 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