Web & iOS dev – Ruby, Rails, RubyMotion & React

Paul Sturgess

Logging to the Console in RubyMotion

The simplest way to output to the console from your RubyMotion app is to use puts. This works fine when your app is running in the simulator. However, puts does not output to the console when your app is running on the device itself.

You can view the live logs while your app is running on your usb connected device via:

$ motion device:console

You will see messages from your application alongside those from other apps or the system itself.

Instead of using puts, you’ll need to make use of NSLog. For example

NSLog("My debug messge")

Note, however, that the first argument for NSLog is actually a String Format Specifier.

The following are equivalent:

puts "A #{variable} goes here"
NSLog("A %@ goes here", variable)

Just remember that any NSLog messages you leave in your app will be visible to the curious, even after you’ve released to the App Store.