Search Unity

[RELEASED] Debug.Log Extensions

Discussion in 'Assets and Asset Store' started by SisusCo, Mar 17, 2020.

  1. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    413
    title.png

    Enhance the Debug class with numerous improvements that can greatly improve readability in the Console and save a lot of time by enabling more compact debugging code to be used.

    This is a plug & play solution; all Debug commands in your classes will automatically switch to using the new and improved versions.

    Asset Store - Buy Debug.Log Extensions
    Webpage - Find the blog, contact information...
    Join Mailing List - Be in the know


    Features
    ☑ Clean Console
    Stack traces are no longer visible for every entry in the Console list. This greatly improves readability.
    ☑ Syntax Highlighting
    Your console messages are automatically augmented with colorful syntax highlighting, improving readability even more.

    ☑ Automatic Context
    The context Object is automatically determined for your messages whenever possible to help with locating message sources.

    ☑ Channels
    Prefix a log message with a tag inside square brackets to tie it to a specific channel, then show/hide all messages from specific channels.

    ☑ Debug.Log(()=>field)
    A new compact syntax can be used to log both the name and value of a field to the console.

    ☑ Debug.LogChanges(()=>field)
    Have messages be printed automatically whenever the value of a field changes.

    ☑ Debug.LogState(target)
    Easily print the full state of a target to the console.

    ☑ Debug.DisplayOnScreen(()=>field)
    Easily display the name and current value of any field on the screen.

    ☑ Debug.LogToFile(message, path)
    Easily output messages into text files instead of the console.

    ☑ Dev.Log(message)
    Just like Debug.Log except all calls are omitted from release builds.
    ☑ Critical.Log(message)
    Useful for important messages you don't want getting lost in the shuffle; uses a larger font, full stack trace and always gets recorded in a log file.

    ☑ Personal Channel
    Use your personal channel to log messages that are by default omitted from all users except for you.

    ☑ Highly Customizable
    Thorough customization options allow you to configure everything to fit your team as well as your personal preferences.

    ☑ Console+
    As an added bonus you get an augmented Console window with a new control for toggling channels on/off.

    Usage Examples

    ☹ Before:​
    Code (CSharp):
    1. Debug.Log(nameof(target)+"="+(target == null ? "null" : target.ToString()), this);

    ☑ After:​
    Code (CSharp):
    1. Debug.Log(()=>target);

    ⚠ Prints:​
    target=Player​


    ☹ Before:​
    Code (CSharp):
    1. string message = "MyClass state:\n";
    2. message += "speed=" + speed + "\n";
    3. message += "target=" + (target == null ? "null" : target.ToString()) + "\n";
    4. message += "progress=" + progress;
    5. Debug.Log(message, this);

    ☑ After:​
    Code (CSharp):
    1. Debug.LogState(this);

    ⚠ Prints:​
    MyClass state:
    speed=5
    target=null
    progress=0.25​


    ☹ Before:​
    Code (CSharp):
    1. void Update()
    2. {
    3. if(myField != lastValue)
    4. {
    5.   Debug.Log("myField="+(lastValue = myField)+"\n(was: "+lastValue+")", this);
    6.   lastValue = myField;
    7. }
    8. }

    ☑ After:​
    Code (CSharp):
    1. Debug.LogChanges(()=>myField);

    ⚠ Prints:​
    myField=5
    (was: 4)
    myField=6
    (was: 5)​

    Installation

    Once you have installed Debug.Log Extensions you will be asked whether or not you would like to replace the default Debug class across the project.

    If you choose "Yes" and some classes in your project contain the statement "using Debug = UnityEngine.Debug;" it can prevent the project from compiling.
    To fix this you just need to remove the statements from your code - they should no longer be necessary when using Debug.Log Extensions anyways.

    Alternatively you can opt not to replace the default Debug class. In this case you will need to add "using Debug = Sisus.Debugging.Debug;" in any classes where you want to enable Debug.Log Extensions' enhancements.​
     
    Last edited: Mar 18, 2020
  2. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    413
    Update 1.1.1 is now out and adds the following improvements:
    • Extended Debug class with several new LogWarning and LogError methods.
    • Extended Dev class with several new methods.
    • Improved syntax formatting logic.
    • Improved UnityEngine.Object formatting in Log messages.
    • Improved automatic context Object fetching.
     
  3. Jh2556

    Jh2556

    Joined:
    Sep 29, 2014
    Posts:
    1
    Hello! Thanks for this great tool, pretty much just what I was looking for.

    I had a question though. Aside from Dev.Log is there a way of automatically disabling all logs from builds; debug/non-debug.

    I know there are some risks/implications with this, but it'd be very helpful and would save a lot of time from rewriting all the logs when using your tool in large large projects.

    Thanks!
     
  4. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    413
    Hi there @Jh2556 ! I'm glad to hear you've found the asset useful.


    I actually have been considering adding an option that would allow omitting all Debug method calls from release builds. I've been thinking I could also enable this mode automatically whenever the Use Player Log setting is set to false, since all those method calls are just wasted resources in that context anyways.

    Critical.Log should also work together well with this approach, since you could still use it to log a couple of very important errors into a custom Log file for end users, even if all normal Debug.Log calls have been omitted.


    Are you in a hurry to get this functionality? I'm a bit busy with other things right now, but I could start implementing this functionality in about a week's time I think.
     
unityunity