Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

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

Discussion in 'Scripting' started by guitarxe, May 14, 2014.

  1. guitarxe

    guitarxe

    Joined:
    Dec 1, 2013
    Posts:
    131
    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?
     
  2. mael5trom

    mael5trom

    Joined:
    Feb 27, 2014
    Posts:
    16
    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.
     
  3. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    I usually dump all Log and most LogWarning.

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

    novashot

    Joined:
    Dec 12, 2009
    Posts:
    373
    Last edited: May 14, 2014
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    You can do that by disabling "use player log" in the player settings.

    --Eric
     
  6. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    I cannot find that option for iOS and Android... Should one assume it's turned off by default on those platform?
     
    GuirieSanchez likes this.
  7. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    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.
     
    ramand likes this.
  8. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    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.
     
  9. robinwood

    robinwood

    Joined:
    Dec 2, 2015
    Posts:
    18
    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!