Get log from iOS15 device

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?

I write the logs and recover them but only of the current instance!

Indeed.

If the app crashes or is closed, the old logs are deleted

They may or may not be deleted — the unified logging system has some complex logic for determining when log entries get purged — but you definitely don’t have access to them. The .currentProcessIdentifier scope means what it says: It gives you log entries for this process only.

If you’d like to see this improve in the future — it’d be nice if there were a ‘this app run by this user’ scope — I encourage you to file an enhancement request describing your requirements.

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"

Thank you very much, but for now I'll write directly to a file avoiding OSLog.

They may or may not be deleted — the unified logging system has some complex logic for determining when log entries get purged — but you definitely don’t have access to them. The .currentProcessIdentifier scope means what it says: It gives you log entries for this process only.

If you’d like to see this improve in the future — it’d be nice if there were a ‘this app run by this user’ scope — I encourage you to file an enhancement request describing your requirements.

Seeing as iOS 16 just dropped I was wondering if you were aware if any such enhancement had been made in the latest update? Haven't got a chance to investigate this myself so posting here to allow the community to respond.

Hey, any update on this?

Get log from iOS15 device
 
 
Q