Can I use OSLogStore to access logs from earlier runs of my app?

I understand that in iOS 15 and macOS Monterey, I can easily access the log system to get log entries for my app like this:

let store = try OSLogStore(scope: .currentProcessIdentifier)

I can then query store for the log entries.

However, as it says right in the name, the store is only for current process, i.e current run of my app. When I try to get entries, I only get entries from the current run, even if I specify an earlier time like this:

guard let positionDate = Calendar.current.date(byAdding: .day, value: -7, to: Date()) else { return }
let position = store.position(date: positionDate)
let predicate = NSPredicate(format: "subsystem == 'com.exampl.emyAppSubsystem'")
let entries = try store.getEntries(with: [], at: position, matching: predicate)
for entry in entries {
   print("Entry: \(entry.date) \(entry.composedMessage)")
}

Is there any way to access log entries for earlier runs of my app, e.g from days or weeks ago? Either on macOS or iOS?

Replies

Is there any way to access log entries for earlier runs of my app, e.g from days or weeks ago? Either on macOS or iOS?

On macOS you can do this by opening the .system scope — or, on systems prior to macOS 12 beta, by calling OSLogStore.local() — and then running a query for your process name. IIRC this only works if you’re running as an admin user.

I don’t think there’s a solution for iOS but that would, IMO, make a good enhancement request.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"