Debug logging with Xcode 4 breakpoints

Jonah Williams ·

NSLog calls do not belong in release builds. Logging is slow and the performance impact of log statements on a device can be considerable. Logging is also noisy, it can obscure useful debugging information and may leak information you would rather not expose in a release build. Looking at my device’s system log I see output full of content urls, api keys, massive log messages, and data only valuable while debugging an app.

: Succeeded! Received 18977 bytes of data for url http://www…
: fetched comments: ( …<74k of JSON>
: *** …GetData: http://…/query?id=1001&sc=17&fields=…&apiKey=
: applicationDidBecomeActive completed
: JSON parsing finished in 24 ms. String alloc took 2 ms. Comment stripping took 1 ms.
: CallbackHandler registered delegate,, instance=0x263650

There are a number of examples of using precompiler macros to eliminate log output on non-debug builds but I recently started using Xcode 4’s breakpoints and find them to be my favorite mechanism. Breakpoints can be configured to log arbitrary output and automatically continue to avoid stopping program execution. They can be dragged from one line to another, added, disabled, and removed while your app is running. You can even check them in as part of your project to share them with other developers.

Console logging with breakpoints
Create a new breakpoint by clicking in the source editor’s gutter.
Control-click the breakpoint to edit its behavior.

When hit the example breakpoint above will log -didReceiveMemoryWarning my title is "Demo!" to the console.

Sharing breakpoints
In the breakpoint navigator control-click a breakpoint to share it as part of a workspace.
Shared breakpoints are stored in .xcworkspace/xcshareddata/xcdebugger/Breakpoints.xcbkptlist


I’ve found breakpoints to be a great way to log debug information about the app in a configuration which I can choose to share with my team and which runs no risk of appearing in a release build. The breakpoints navigator gives me an easy way to jump to any of these log statements and it is trivial to switch a breakpoint from just logging to pausing the app so I can debug in depth. I’ll still use NSLog for exceptional conditions I want to report in any build but so far you won’t find a single one in my current project.

Have you found a NSLog alternative you are happy with? Is there anything you couldn’t replace with logging breakpoints instead?

What can we help you with?

Tell us a bit about your project, or just shoot us an email.

Interested in a Career at Carbon Five? Check out our job openings.