Where does output from print statements gp when the app is running on the device?

I know that print statements for debugging/testing should be commented out before building for a device like an iPhone.
But during intermediate testing it’s sometimes a pain to comment them out when you just want to test your non-finished app runs on the iPhone.

So I was just wondering…

Where does output from print statements gp when the app is running on the device? Is there some way to see the output (a log file somewhere)?

Also would print statement is code be a memory leak? [import]uid: 295 topic_id: 1652 reply_id: 301652[/import]

My understanding is it doesn’t ‘go’ anywhere. It does, however, produce a performance hit.
There are methods where you can check to see if your in the simulator or not and use if statements and a global boolean to not output print statements on a real device. [import]uid: 7467 topic_id: 1652 reply_id: 4900[/import]

I think you can get them in from the logs in the organizer, but I don’t have a iOS device near by to test with. In the xcode sim though print statements go into the system log. Which is viewable via console.app or in /var/log/ [import]uid: 3 topic_id: 1652 reply_id: 4902[/import]

You an see the print statements on the Xcode console if you have the IOS device connected to your computer. The output is buffered so you may not see it until the output buffer is full or you quit the app. You can force the output in real-time by adding the following at the top of your code:
io.output():setvbuf(“no”)

This may affect performance so you shouldn’t leave it in your code. To my knowledge there is no log kept of print outputs if the device is not connected to computer.

-Tom [import]uid: 7559 topic_id: 1652 reply_id: 4973[/import]

Hi,

I have many print statements for debugging in my code, particularly around memory usage.

What would be cool is to have a config entry in the config.lua file to say strip out print statements and then the compiler does this automaticlly?

This would one a one-liner in the compiler! …compared to having many “if(!debugmode)then print “xxx”” lines in app code. – This way I can leave debugging in.

Alternativly for now I will probably write a tool to scan the folder and stip out the print statements and comments placing the application in a publish folder.

I welcome comments for how anyone else deals with print statements??

J
[import]uid: 9640 topic_id: 1652 reply_id: 7930[/import]

I used this on top of my code to disable all print commands (this overrides the built-in print function with an empty function):

if debug == false then print = function() end end  

or just

print = function() end  

Works fine. [import]uid: 9644 topic_id: 1652 reply_id: 7934[/import]

Cool!! - excellent tip :slight_smile: [import]uid: 9640 topic_id: 1652 reply_id: 7941[/import]

Setting “print” to a empty function is a good way to eliminate all prints from your final code. You can also created a print_all function to force some print statements to always happen.

local print\_all = print  
  
print = function() end -- comment out this statement to enable print statements  
  
print\_all( "This will always print" )  

-Tom [import]uid: 7559 topic_id: 1652 reply_id: 7945[/import]