I've set up logging through OSLog in my iOS App, and I've added a button to export logs with OSLogStore:
extension OSLog {
private static let subsystem = Bundle.main.bundleIdentifier!
@available(iOS 15.0, *)
static func getLogs(inLast: TimeInterval) -> [OSLogEntryLog]? {
guard let store = try? OSLogStore(scope: .currentProcessIdentifier) else { return nil }
let startTime = store.position(timeIntervalSinceEnd: -inLast)
guard let entries = try? store.getEntries(at: startTime).compactMap({ $0 as? OSLogEntryLog }).filter({ $0.subsystem == subsystem }) else { return nil }
return entries
}
}
This works fine when testing locally, all logs are exported even in release builds. However, when our team is testing builds through TestFlight, debug logs are not exported. Is there a way to export all logs including debug logs?
You need to add this to your Info.plist
<key>OSLogPreferences</key>
<dict>
<key>your.subsystem.key.here</key>
<dict>
<key>your-category-here</key>
<dict>
<key>Level</key>
<dict>
<key>Enable</key>
<string>Debug</string>
<key>Persist</key>
<string>Debug</string>
</dict>
</dict>
</dict>
</dict>
Also, you might want to add
<key>Enable-Private-Data</key>
<true/>
to the same dictionary to not have all your parameters redacted.
And finally, don't use .filter on the getEntries() result, it's extremely slow. Instead use the matching overload with a NSPredicate, e.g.
try? store
.getEntries(
at: startTime,
matching: NSPredicate(format: "subsystem == \"\(subsystem)\"")
)
.compactMap({ $0 as? OSLogEntryLog })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With