Do you leave your Debug.Log() lines commented in the code, or remove them?

Hi folks, quick question here to some of the more experienced programmers out there.
Myself, I am just a newbie, and I have noticed that my code is often quite cluttered with commented Debug.Log() lines that I used during the writing of the script, and then commented when finished, but left in the code in case I would like to debug this again at a later time (which I often do).

I’m just curious to know what professionals do in this case. Do they remove the debug lines entirely once a class is deemed “working as intended”, or something else?

I have a singleton global helper script that stays constant across the application. In the script, there is a boolean to tick/check to enable debugging at any time. Then where I wrap an if around IsDebuggingEnabled boolean to print out the debug info. I’ve found that depending on the amount of debugging stuff being thrown to logs there can be a performance hit when running on a mobile device. So this method gets me debugging when necessary, and allows me to disable all when i publish without finding and uncommenting all.

I usually dump all Log and most LogWarning.

I leave the LogWarning/LogError that are meaningful to data integration.

I thought I read on the forums here somewhere that Debug.Log would create performance issue and should be commented out or deleted for production… but i been wrong before

http://forum.unity3d.com/threads/159108-Shoul-i-delete-Debug-log-for-final-version

http://answers.unity3d.com/questions/126315/debuglog-in-build.html

You can do that by disabling “use player log” in the player settings.

–Eric

I cannot find that option for iOS and Android… Should one assume it’s turned off by default on those platform?

1 Like

I know I’ve dug console logs out of the device before, and Debug.Log’s definitely show up there, with all their stacktraces included. So the default setting on that (I can’t find it in my Player settings, either) is clearly the one that’s going to be super slow.

1 Like

Kinda suck that there’s no master switch to turn it off on mobile… I have a feeling I know what I’ll do this week on 3 different projects.

Usally i will leave my Debug.Log() lines in the codes. But as you know, too many logs will lead a performance issue when running on mobile devices.

So i have made a tool to solve this problem. With it, we can disable logs in builds with 1-click.

Enjoy it!