Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feature Request Encapsulated Debug.Log Stacktrace reduction

Discussion in 'Editor & General Support' started by Santifocus, Sep 11, 2021.

  1. Santifocus

    Santifocus

    Joined:
    Oct 13, 2018
    Posts:
    6
    Hello there, both in my hobby project and my project at work we have encapsulated Debug.Log/ Debug.LogError etc. in a seperate class to have better control over what and how we Log information, furthermore we added the System.Diagnostics.Conditonal Attribute to all methods in case we want to disable logging entirely.
    This however causes the effect that:
    1. The logged stacktrace includes the method calls inside the class that encapsulates Debug.Log
    2. Doubleclicking the log will jump to the final method that called Debug.Log
    Sadly compiling the logger class in its own libary is not a possibility because of the Conditonal Attribute.

    Therefore I decided to make a feature request for an extra overload for all Debug.Log methods accepting an int which should then exlcude the last X method stacktraces, which obviously should also cause the double click to jump to the script that called the encapsulating class.

    For example:
    Code (CSharp):
    1. [Error]: An Error occured.
    2. UnityEngine.Debug:LogError (object,UnityEngine.Object)
    3. EoE.Runtime.Tools.DLogger:Log (string,UnityEngine.Object,EoE.Runtime.Enums.LogLevel) (at Assets/Scripts/Runtime/Tools/DLogger.cs:151)
    4. EoE.Runtime.Tools.DLogger:Log (object,EoE.Runtime.Enums.LogLevel) (at Assets/Scripts/Runtime/Tools/DLogger.cs:39)
    5. EoE.Runtime.MonoBehaviours.CameraControllers.AnchoredCameraController:Awake () (at Assets/Scripts/Runtime/MonoBehaviours/CameraControllers/AnchoredCameraController.cs:43)
    Instead when calling the new overload with Debug.LogError("An Error occured", 2) it should then reduce the stacktrace to:
    Code (CSharp):
    1. [Error]: An Error occured.
    2. UnityEngine.Debug:LogError (object,UnityEngine.Object)
    3. EoE.Runtime.MonoBehaviours.CameraControllers.AnchoredCameraController:Awake () (at Assets/Scripts/Runtime/MonoBehaviours/CameraControllers/AnchoredCameraController.cs:43)
    Greetings,
    Lucas
     
  2. Santifocus

    Santifocus

    Joined:
    Oct 13, 2018
    Posts:
    6