Will OSLogStore work on iOS without the com.apple.private.logging.admin entitlement?

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:

Code Block swift
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)
    // FB8518476: The Swift shims for for the entries enumerator are missing.
    let allEntries = try Array(logStore.__entriesEnumerator(position: oneHourAgo, predicate: nil))
  // 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:

Code Block
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:

Code Block
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?
Post marked as unsolved Up vote post of steipete Down vote post of steipete

3 Replies

Tested with Xcode 12b6, same issue.

I wrote about this bug and others in a post on my blog, steipete.com "Logging in Swift"
I think we are close! Apple, please fix at least the OSLogStore for iOS 🙏
It would be good if Apple would implement shipping logs off device, since https://github.com/apple/swift-log specifically highlights that overlaying swift-log over os_log is not a good idea. Allegedly there is a path to unify the two, but this would seem like a big gap if it’s not unified before Big Sir / iOS 14 drops.