Swift

Getting More Logs From Xcode

Xcode has a number of logging features I’ve found help me figure out why various things are failing over the years. It’s usually (and by usually I mean always) due to something stupid I did, but the logs help me figure out what’s going on pretty quickly.

So first up, let’s look at enabling the activity logs. To do this, we’ll send an EnableDebugActivityLogs Boolean variable into com.apple.dt.XCBuild.plist:

defaults write com.apple.dt.XCBuild EnableDebugActivityLogs -bool YES

Now let’s turn on the build debugging mode. Now, for the above command you can leave it on without a performance hit, but this one should be turned on and off as you’re going as you’ll be capturing a lot of traces which slows down the build process. To turn it on we’ll send a boolean YES to the EnableBuildDebugging key in com.apple.dt.XCBuild and to disable you’d flip that back to a NO or delete the key:

defaults write com.apple.dt.XCBuild EnableBuildDebugging -bool YES

Next, let’s look at prebuild steps. The IDE can show logs for prebuilding projects. To enable, use the defaults command and set the IDEShowPrebuildLogs in com.apple.dt.Xcode.plist as a boolean and set to YES as follows:

defaults write com.apple.dt.Xcode IDEShowPrebuildLogs -bool YES

Next, we’ll send logs for SourceKit indexing into /tmp: sources (you can disable indexing if this is failing but usually that just causes issues later so you might be better off figuring out why indexing is failing). In my experience this is usually due to an issue with a module that causes a broken header:

defaults write com.apple.dt.Xcode IDESourceKitServiceLogLevel -int 2

Finally, you can turn on a debugging menu with all kinds of options in Xcode. To do so, add a ShowDVTDebugMenu key to com.apple.dt.Xcode.plist and set it as a boolean to YES:

defaults write com.apple.dt.Xcode ShowDVTDebugMenu -bool YES

There are other options as well, and there are options within given frameworks, so please feel free to throw a comment out there and I’ll add them if you have some techniques you like to use!