It seems that OSLogStore allows accessing logs on both macOS (AppKit), macOS (Catalyst) and iOS. Currently it works on both mac variants, but it fails with an entitlement error on iOS.
Sample Code:
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 }
}
When running on the iOS Simulator, the following error is thrown:
Error Domain=OSLogErrorDomain Code=9
"Client lacks entitlement to perform operation"
UserInfo={NSLocalizedDescription=Client lacks entitlement
to perform operation, _OSLogErrorInternalCode=14}
When running on an iOS Device, the error message is slightly different:
Error Error Domain=NSCocoaErrorDomain Code=4099
"The connection to service on pid 0 named com.apple.OSLogService
was invalidated." UserInfo={NSDebugDescription=The connection to
service on pid 0 named com.apple.OSLogService was invalidated.}
If you are looking for a complete test sample, Ole Begemann created a useful one. https://github.com/ole/OSLogStoreTest
Is this a bug or will we need to request a special entitlement to access app-internal logs in our app?