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

Question Should we disable Debug.log for a public build ?

Discussion in 'Editor & General Support' started by Pytchoun, Mar 11, 2023.

  1. Pytchoun

    Pytchoun

    Joined:
    Apr 12, 2015
    Posts:
    203
    Should we for performance reason or it isn't a problem ?
     
  2. tsibiski

    tsibiski

    Joined:
    Jul 11, 2016
    Posts:
    569
    If you output log anywhere inside update methods, or any other logic that runs several times a second, you should. Debug.Log has a suprisingly negative effect on performance.

    Here's how I handle it


    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public static class StaticRunOnGameLoad
    4. {
    5.     /// <summary>
    6.     /// Gain performance on regular code execution outside of editor by disabling Debug logger.
    7.     /// </summary>
    8.     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
    9.     public static void DisableLoggerOutsideOfEditor()
    10.     {
    11. #if UNITY_EDITOR || DEVELOPMENT_BUILD
    12.         Debug.unityLogger.logEnabled = true;
    13. #else
    14.         Debug.unityLogger.logEnabled = false;
    15. #endif
    16.     }
    17. }
     
    Last edited: Mar 11, 2023
    Homicide likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    The best answer is "yes, get them all out of there," but in practice as long as it's only in Start() and not massive sheetes of text, you should be fine.

    Just know that if you print any "interesting" information out there, it is observable by the user, such as login tokens or other such credentials.

    Personally I usually leave all the Start() stuff in, but I'll guard spammy stuff with either:

    Code (csharp):
    1. #if UNITY_EDITOR
    2. #endif
    or else

    Code (csharp):
    1. if (Application.isEditor)
    2. {
    3. }
     
  4. LethalGenes

    LethalGenes

    Joined:
    Jan 31, 2023
    Posts:
    69
    Having debugs firing slows performance in editor aswell ! Debug is like a resource. You debug something you regularly need the information of but do not want to use inspector for, or you debug something that you are currently working on; in order to figure it out.
    Therefor if you feel a dev might want to deactivate this line for performance but still remember this line to save rewriting it- then you can use the // or /*<your line>*/ and skip the reading of it.

    Won’t matter much at all if it’s in the code but not firing If it’s important for the programmer to resume work here. But to fire it for the console result would only ever be useful in editor. Unless you hooked up a console for use in game. So active debug logs should always be removed after they have served their use.