Hello folks,
I would like to incrementally retrieve logs of my iOS App from the Unified Logging System using OSLogStore.
First I initialize the store
store = try OSLogStore(scope: .currentProcessIdentifier)
Second I set a position from which I want the logs using either :
position = store.position(timeIntervalSinceLatestBoot: 0) // to get the logs from the launch of the App
position = store.position(date: Date().addingTimeInterval(-10)) // to get the logs of the last 10 seconds
Third I get the entries in the store from the position
store.getEntries(at: position)
Issue
Whatever the position I set using from OSLogStore:
position(timeIntervalSinceLatestBoot:)
position(date:)
position(timeIntervalSinceEnd:)
All the logs are retrieved. I cannot get only the subset requested by the timeframe I specified
Sample
A sample LogScreen that has 2 buttons is attached to the post
1 to fetch logs since the last time they have been fetched
1 to add a log
The code has been simplified to ease the comprehension of the case, please be indulgent to the shortcuts that have been taken.
LogScreen.swift
References
https://developer.apple.com/documentation/oslog/oslogstore
https://developer.apple.com/forums/thread/705868
https://developer.apple.com/videos/play/wwdc2023/10226/
Environment
XCode 15b7
iPhone 14 Pro / iOS 17