Getting unified system logs from an iOS device

823 views Asked by At

I'm trying to use unified logging to log messages and retrieve them from a device for inspection. I created a new OSLog instance with

let logDebug = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "⚠️ debug")

Then I log messages with

os_log("%@", log: logDebug, type: OSLogType.debug, String(format:message, arguments: formatArgs))

This works fine in the Xcode console. It's supposed to be possible to retrieve these logs from an Xcode device by

  • Doing a sysdiagnose (as Apple explains here)
  • Transferring the sysdiagnose to a Mac, and then
  • Inspecting the log (in system_logs.logarchive) with Console.app or the log command line tool.

When I do this, none of my logs are shown. No logs with the expected subsystem (bundle ID) are shown.

However, if I examine the log files in system_logs.logarchive directly via grep or vim, the messages are present. So they're in the logs, but for some reason neither Console.app nor log will show them. I made sure that Console.app is set to show "all messages" and I haven't entered any search terms.

What step am I missing, or what detail needs to be different?

1

There are 1 answers

0
E.Coms On

It seems you have no luck with OSLogType.debug. Console cannot show this kind of log.

But others work perfectly. Please try then check them in Console app. os_log("%@", log: logDebug, type: OSLogType.info, String(format:"%i", arguments: [1]))

os_log("%@", log: logDebug, type: OSLogType.error, String(format:"%i", arguments: [1]))

even:

os_log("%@", log: logDebug, type: OSLogType.default, String(format:"%i", arguments: [6]))