Hi, I need to retrieve the app logs in a file to be sent via API only when needed.
I write the logs and recover them but only of the current instance! If the app crashes or is closed, the old logs are deleted while I have to recover them at the next start.
I write log with Logger and recover them with OSLogStore.
here a sample snippet to write
func testLog(_ message: String){
let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "myAppLog")
logger.error("Sample error msg")
}
and the snippet to load
func getLogEntries() throws -> [OSLogEntryLog] {
let logStore = try OSLogStore(scope: .currentProcessIdentifier)
let oneDayAgo = logStore.position(date: Date().addingTimeInterval(-3600*24))
let allEntries = try logStore.getEntries(at: oneDayAgo)
return allEntries
.compactMap { $0 as? OSLogEntryLog }
.filter { $0.subsystem == Logger.subsystem }
}
any clue?