27

I'm trying to get some logging out of my app through Unified Logging (os_log)

Here's the initialization of the log:

var osLog : OSLog = OSLog(subsystem: "com.test.testapp", category: "native-tester") 

And here's how I use it:

os_log("iOS App initialized successfully!", log: osLog, type:.info) 

When debugging the app normally, the logs appear properly on the console output, but when I look at the device console (Shown in the "Devices and Simulators" window) I don't see them at all.

This article says that you should configure the system to enable the debug logs using

sudo log config --mode "level:debug" --subsystem com.test.testapp 

But that didn't seem to make a difference. I'm guessing it's because I'm configuring the mac to view the logs, not the iPad.

How do I view the ipad / iphone logs from os_log in the device console?

6 Answers 6

46

The "Devices and Simulators" window only shows crash reports. Use the Console app or Terminal, via the log --stream command, to see live log output.

To see the device's live log messages via the Console app, either when running from Xcode or when running from the device directly:

  • Open Console.app.
  • Click on the device's name in the left side panel, under "Devices".
  • Select Action, then Include Info Messages from the menu. If you are also using .debug level messages, make sure to select Include Debug Messages as well. (Without those items selected, the Console displays .default, .fault, and .error level messages only.)

If you still don't see the messages, try entering this Terminal command to configure the logging levels for your app:

sudo log config --subsystem com.test.testapp --mode level:debug 

This turns on .debug-level logging for subsystem "com.test.testapp" (which includes .info and .default messages).

If you want to persist the messages, rather than the default of memory-only, turn on persistence for the three levels at the same time, like so:

sudo log config --subsystem com.test.testapp --mode level:debug,persist:debug 

Regardless of any log settings, though, only crash reports will appear in the "Devices and Simulators" window.

Sign up to request clarification or add additional context in comments.

1 Comment

There is also a radar that debug logs not showing up in the console app even though they are turned on if running on a simulator. Only showing up for real devices forums.developer.apple.com/thread/82736
24

Another pitfall: If you have set OS_ACTIVITY_MODE to disable in your scheme, then you will not see any logs for your app in console.

You have to remove or uncheck that argument.

2 Comments

There is a question on how to disable logging where this variable is mentioned in a comment stackoverflow.com/questions/41142848/…
This is what got me, this was disabled for Firebase Debug View to work, thanks!
10

In the console app, there are two options to include / hide debug and info messages:

enter image description here

Comments

8

Log types .debug and .info are by default memory only (not saved on disk) so it won't be visible on the device console.

Detailed info: https://developer.apple.com/documentation/os/logging?language=objc

Also here is pretty nice WWDC: https://developer.apple.com/videos/play/wwdc2016/721/

1 Comment

So what is the purpose of saving to memory only if it's not accessible? If it is accessible, how?
2

Following screenshots could be helpful for reference- enter image description here

enter image description here

Comments

-3

My os_log went missing after releasing an app to app store. I guess when I built the app for release, the debug option was turned off.

To enable the logging back... go to Product > Scheme > Edit Scheme > Run Debug ... then check Debug executable.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.