Disabling print

Hi,
I’m trying to turn off all my debug message a.k.a print statements. I read couple of days ago about a trick with one line to toggle your print on/off. Sadly, I can’t find it after furiously googled for about an hour :frowning:

All i can came up is having a local print=function() but then I need to write this on all my luas.

Any help?
thanks
[import]uid: 76697 topic_id: 36131 reply_id: 336131[/import]

yanuar, I think you are looking for something similar to what was mentioned here by Rob Miracle, http://developer.coronalabs.com/forum/2013/02/06/some-misc-newbie-type-questions#comment-141918

Here’s what he suggested:

"I wouldn’t go and delete all your print statements. Instead before you deploy live, you could at the top of your main.lua add something like:

[blockcode]print = function() return true end[/blockcode]

Which would basically short-circuit the system’s print statement which would have the effect of turning off your print. I personally use a little more complicated version of this in my apps:

[blockcode]
local debugMode = true
cachePrint = print
function print(…)
if debugMode then
cachePrint(unpack(arg))
end
end
[/blockcode]

And I just have to set the value of debugMode to either true or false."

Hope that helps. [import]uid: 208407 topic_id: 36131 reply_id: 143508[/import]

cool, thanks [import]uid: 76697 topic_id: 36131 reply_id: 143541[/import]

Neat bit of code there. Is there any reason for concern over performance in either method? i.e. is the software spending any cycles evaluating the if debugMode or going to a function that doesn’t really do anything for every print statement? [import]uid: 213270 topic_id: 36131 reply_id: 143550[/import]

mike.rp99, anytime an if…then statement is being evaluated its going to take a finite amount of time and processing power to accomplish. That said, these methods should not add any noticeable overhead to an app. The best thing to do is test it in your code to make sure everything performs the way you want it too. [import]uid: 208407 topic_id: 36131 reply_id: 143614[/import]

yanuar, I think you are looking for something similar to what was mentioned here by Rob Miracle, http://developer.coronalabs.com/forum/2013/02/06/some-misc-newbie-type-questions#comment-141918

Here’s what he suggested:

"I wouldn’t go and delete all your print statements. Instead before you deploy live, you could at the top of your main.lua add something like:

[blockcode]print = function() return true end[/blockcode]

Which would basically short-circuit the system’s print statement which would have the effect of turning off your print. I personally use a little more complicated version of this in my apps:

[blockcode]
local debugMode = true
cachePrint = print
function print(…)
if debugMode then
cachePrint(unpack(arg))
end
end
[/blockcode]

And I just have to set the value of debugMode to either true or false."

Hope that helps. [import]uid: 208407 topic_id: 36131 reply_id: 143508[/import]

cool, thanks [import]uid: 76697 topic_id: 36131 reply_id: 143541[/import]

Neat bit of code there. Is there any reason for concern over performance in either method? i.e. is the software spending any cycles evaluating the if debugMode or going to a function that doesn’t really do anything for every print statement? [import]uid: 213270 topic_id: 36131 reply_id: 143550[/import]

mike.rp99, anytime an if…then statement is being evaluated its going to take a finite amount of time and processing power to accomplish. That said, these methods should not add any noticeable overhead to an app. The best thing to do is test it in your code to make sure everything performs the way you want it too. [import]uid: 208407 topic_id: 36131 reply_id: 143614[/import]

yanuar, I think you are looking for something similar to what was mentioned here by Rob Miracle, http://developer.coronalabs.com/forum/2013/02/06/some-misc-newbie-type-questions#comment-141918

Here’s what he suggested:

"I wouldn’t go and delete all your print statements. Instead before you deploy live, you could at the top of your main.lua add something like:

[blockcode]print = function() return true end[/blockcode]

Which would basically short-circuit the system’s print statement which would have the effect of turning off your print. I personally use a little more complicated version of this in my apps:

[blockcode]
local debugMode = true
cachePrint = print
function print(…)
if debugMode then
cachePrint(unpack(arg))
end
end
[/blockcode]

And I just have to set the value of debugMode to either true or false."

Hope that helps. [import]uid: 208407 topic_id: 36131 reply_id: 143508[/import]

cool, thanks [import]uid: 76697 topic_id: 36131 reply_id: 143541[/import]

Neat bit of code there. Is there any reason for concern over performance in either method? i.e. is the software spending any cycles evaluating the if debugMode or going to a function that doesn’t really do anything for every print statement? [import]uid: 213270 topic_id: 36131 reply_id: 143550[/import]

mike.rp99, anytime an if…then statement is being evaluated its going to take a finite amount of time and processing power to accomplish. That said, these methods should not add any noticeable overhead to an app. The best thing to do is test it in your code to make sure everything performs the way you want it too. [import]uid: 208407 topic_id: 36131 reply_id: 143614[/import]

yanuar, I think you are looking for something similar to what was mentioned here by Rob Miracle, http://developer.coronalabs.com/forum/2013/02/06/some-misc-newbie-type-questions#comment-141918

Here’s what he suggested:

"I wouldn’t go and delete all your print statements. Instead before you deploy live, you could at the top of your main.lua add something like:

[blockcode]print = function() return true end[/blockcode]

Which would basically short-circuit the system’s print statement which would have the effect of turning off your print. I personally use a little more complicated version of this in my apps:

[blockcode]
local debugMode = true
cachePrint = print
function print(…)
if debugMode then
cachePrint(unpack(arg))
end
end
[/blockcode]

And I just have to set the value of debugMode to either true or false."

Hope that helps. [import]uid: 208407 topic_id: 36131 reply_id: 143508[/import]

cool, thanks [import]uid: 76697 topic_id: 36131 reply_id: 143541[/import]

Neat bit of code there. Is there any reason for concern over performance in either method? i.e. is the software spending any cycles evaluating the if debugMode or going to a function that doesn’t really do anything for every print statement? [import]uid: 213270 topic_id: 36131 reply_id: 143550[/import]

mike.rp99, anytime an if…then statement is being evaluated its going to take a finite amount of time and processing power to accomplish. That said, these methods should not add any noticeable overhead to an app. The best thing to do is test it in your code to make sure everything performs the way you want it too. [import]uid: 208407 topic_id: 36131 reply_id: 143614[/import]