Can I access system logs from Swift (I want logs for previous runs of my application)

Hi folks,

For accessing the logs, I’m using OSLogStore object. I want to be able to read logs from any previous run of my application.

I can of course do this:

// Open the log store.
var logStore = try OSLogStore(scope: .currentProcessIdentifier)

But this only allows me to retrieve logs from my current running process.

I can also do this:

// Open the log store.
var logStore = try OSLogStore(scope: .system)

But this only works if my App Sandbox entitlement is false. I tried disabling the sandbox, and I was able to get to all the logs (which is good) but according to this page:

https://developer.apple.com/documentation/security/app_sandbox/

it says: To distribute a macOS app through the Mac App Store, you must enable the App Sandbox capability

Since we are planning on distributing our app on the store, this presents a big problem for me.

(I didn't try submitting to TestFlight to see if it's really the case). I don’t know if there are exclusions or ways around this – I don’t see an entitlement that I can add which would allow access to the logs.

Does anyone know a way around this?

Thanks,

David

Does anyone know a way around this?

No, sadly, there’s no solution for your combination of requirements.

Giving a sandboxed app access to the full system log seems like a non-starter. There's way too me sensitive stuff in there.

OTOH, giving your app persistent access to its own logging seems feasible. Your Friend the System Log talks about .currentProcessIdentifier in some detail, and including a reference to the bug asking for exactly that.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks @eskimo - when you're talking about a reference to a bug, I assume you're referring to this comment you made:

iOS has very limited facilities for reading the system log. Currently, an iOS app can only read entries created by that specific process, using .currentProcessIdentifier scope. This is annoying if, say, the app crashed and you want to know what it was doing before the crash. What you need is a way to get all log entries written by your app (r. 57880434)

You mention iOS - I'm working on a mac app - I assume it's the same.

Can you tell me where I can see the details of r. 57880434, so I can see what was mentioned (and if there are updates or suggestions)?

Unfortunately I don't see any way to get access to older logs for my app. My app talks with a server, and the server can request logs for a specific date/time range ("give me logs from yesterday between 2 and 4pm").

David

Can I access system logs from Swift (I want logs for previous runs of my application)
 
 
Q