0

I am using Xcode Version 13.4.1 (13F100) on a MacBook Pro with macOS Monterey 12.4 and programming in Objective-C.

I would like to log debug messages when my app is running on the iPhone device AND is NOT attached to Xcode. I tried OSLog like described here: https://www.avanderlee.com/debugging/oslog-unified-logging/

However when I open the Console App and select my connected iPhone after running the app the log is empty and I have to explicitly click on "Start streaming" only then I can see my log when I start the app again. enter image description here

I would like to log when the iPhone is not connected and the app is running and then close the app and connect the iPhone and see the log from the app run. I don't want live streaming but look into past logs.

Is there a way to do that?

es1
  • 1,231
  • 3
  • 14
  • 27

1 Answers1

0

I wrote to Apple Developer Support and they said the following:

If you log in your code using OSLog, then you can retrieve those messages using the Terminal command ‘log’ later on.

For example, with the device named “iPhone" connected to the Mac, you can retrieve the log info from the last 3 minutes with:

> % sudo log collect --device-name iPhone --last 3m

You can then use Console to look through the saved logs, or you can parse out the log data from the command line with the ‘log' command. See its man page for usage.

Here a link on how to use OSLog: https://www.avanderlee.com/debugging/oslog-unified-logging/

In Objective-C this worked for me:

#import <os/log.h>

os_log(OS_LOG_DEFAULT, "Some message");

I followed Apple Developer Support's advice and it worked for me.

es1
  • 1,231
  • 3
  • 14
  • 27