Is it possible to get OSLog statements on device for a release build? If I launch the app in the simulator or on device from Xcode, the app can read and display its own log statements using the code below. But in an archived build installed on the device, nothing appears. What am I doing wrong? Or is this some sort of privacy limitation by Apple? In other StackOverflow questions, I see people asking how to turn off OSLog logging for release builds, so it sounds like this logs are not automatically omitted for those builds and should be available to me.
public static func getLogEntries(secondsAgo: TimeInterval? = nil) throws -> [OSLogEntryLog] {
let subsystem = Bundle.main.bundleIdentifier
// Open the log store.
let logStore = try OSLogStore(scope: .currentProcessIdentifier)
// Get all the logs from the last so many seconds.
let seconds: TimeInterval = (secondsAgo ?? -600) * -1
let minutesAgo = logStore.position(date: Date().addingTimeInterval(seconds))
// Fetch log objects.
let allEntries = try logStore.getEntries(at: minutesAgo)
// Filter the log to be relevant for our specific subsystem
// and remove other elements (signposts, etc).
return allEntries
.compactMap { $0 as? OSLogEntryLog }
.filter { $0.subsystem == subsystem }
}
Per discussion in the comments, if you want debug level logs you need to add this to your
Info.plist