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. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Debug.Log Extensions

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

  1. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    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...
    Online Documentation - Scripting reference
    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, the ability to find instances of classes in the stack trace and much more.

    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: Apr 2, 2021
  2. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    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:
    18
    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:
    762
    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.
     
  5. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    It took a bit longer than I first anticipated, but version 1.1.2 of Debug.Log Extensions now introduces support for removing all logging done using the extended Debug class from release builds.

    When this new option is enabled in the settings all Debug.Log calls will be completely omitted from release builds, including any evaluation done for their parameters. So the cost of any string concatenations, ToString operations etc. in your Debug.Log calls will also get eliminated.

    As mentioned previously, you can still use the new Critical class to bypass this and log some messages in release builds to custom log files. This works even if you have disabled Use Player Log in Player Settings.


    Additionally the syntax highlighting feature has been improved in the new update. When you log a color to the console the text representation will now be tinted using the color in question.

    debug-log-colorized-colors.png

    Full source code is now also bundled with the download inside a unity package, along with a DLL builder. This means that is now possible for users to extend the Debug class with their own code and then integrate those changes into the DLL. Do note though that doing this would also mean losing the ability to update Debug.Log Extensions to newer versions (at least without losing your own changes), so it is not recommended in most situations. But if I should for example die in a car crash tomorrow it might come in handy :D
     
    DragonCoder likes this.
  6. Jh2556

    Jh2556

    Joined:
    Sep 29, 2014
    Posts:
    18
    Woah!! Thanks for this great update!!! :D (sorry I forgot to reply earlier)
     
    SisusCo likes this.
  7. ben-rasooli

    ben-rasooli

    Joined:
    May 1, 2014
    Posts:
    40
    Hi

    I think there is a bug in the Console+ Tab. Channel filtering does not work. The disabled channels still show up in the console.
    Screen Shot 2020-05-30 at 9.08.56 pm.png
    macOS version: 10.14.6
    Unity version: 2020.1.0b10.3837
    Debug.Log Extensions version: 1.1.2

    Edit:
    I also tried on Unity 2019.3.11f1 and the issue still insists.
     
    Last edited: May 30, 2020
  8. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    Hi Ben!

    The channel dropdown works a bit differently than some of the other controls found on the console window. It doesn't actually filter which ones of existing messages are currently listed on the window. Instead it lets you completely disable all messages that are henceforth logged using certain channels.

    Because messages from disabled channels are completely ignored, you don't take the usual performance hit from them, and they don't cause your log file to grow bigger. So you could have hundreds of messages being logged every minute on all sorts of channels like audio, pathfinding and combat, but only have the channels that you currently care about actually be active.

    The downside is that you can't retroactively recover messages from channels that were disabled when the log call was made.
     
    ben-rasooli likes this.
  9. ben-rasooli

    ben-rasooli

    Joined:
    May 1, 2014
    Posts:
    40
    How can I remove a channel?

    Anytime I create a channel either via code or via Project Settings, the channel is created permanently. Even if I remove it from the Project Settings or the code, it still shows up in the Console+ tab.
     
  10. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    The Console+ window will catch it when you use any channels in your debugging code and automatically adds them to the channels popup. This list is currently serialized so that it doesn't get cleared for an open Console+ window even if scripts are recompiled, you enter play mode or stuff like that. This ensures that your settings for enabled/disabled channels won't get reset every time you toggle play mode, restart the editor etc.

    It looks like this list is a bit too persistent as it stands right now - the only way to clear it is by first closing the Console+ window and then restarting the editor or entering / exiting play mode.

    I'll think of ways on how this could be improved in the future, maybe e.g. by allowing the user to manually clear the list.
     
    ben-rasooli likes this.
  11. Jh2556

    Jh2556

    Joined:
    Sep 29, 2014
    Posts:
    18
    Hi @SisusCo. I've been getting this error in Unity 2019.4.1f1

    upload_2020-9-29_18-31-25.png

    Any thoughts? Thanks!!
     
  12. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    473
    Can I make a request for the Channel filtering to be actually showing/hiding all messages per channel (instead of just for future logs)? Should be more useful that way.

    Also what does the runtime GUI do exactly? Pressing the Insert key in playmode only shows a small white text: "Dynamic" near the top left corner.

    Pretty cool plugin btw. I just purchased!
     
  13. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    Hi @Jh2556

    It seems like this error can occur if your project contains assets with a bad .meta file containing no guid.

    Here are instructions on how you can find any files with missing guids. You'll need to open Windows PowerShell, change the directory to your project's asset directory and run the command given in that link.

    Hope this helps!
     
  14. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    Hi @Creepgin , thanks for the purchase and the feedback :)

    Currently the Console+ is a very simple wrapper on top of the default Console window and does little more than adds that Channel popup menu to the top.

    I wholly agree that having the popup menu actually filter the contents of the window would be really nice, however this would mean having to rewrite almost all the functionality of the default Console window from scratch. And every time Unity would add new updates to their console window I might also have to update my window to have feature parity. For these reasons I've been wary of going with this approach.

    I have actually done some experimenting with this full rewrite approach, and was able to replicate most of the default console window's features. But some features like maybe device attaching could be problematic to replicate. Perhaps I could still finish it up and offer it as an experimental alternative to the wrapper variant, even if it's missing some features though...

    You can press the Insert key multiple times to cycle through three different modes.
    1. In Dynamic mode the GUI will remain hidden except when Debug.DisplayOnScreen or Debug.ShowFps has been used to display something on the screen.
    2. In Always Visible mode the GUI will always remain visible and also becomes interactive, allowing you to enable and disable channels through it.
    3. In Always Hidden mode the GUI will always remain hidden, even if debugging information is being displayed on screen.
     
    Singtaa likes this.
  15. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    473
    Great! Thanks for the clarification. Real tag filtering and regex support may be worth the effort for the standalone new console. ;)
     
  16. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    @Creepgin So, I had a pretty productive weekend and as a result version 1.1.3 is out now with an all-new experimental Console+ window :D

    It can be opened using the menu item Window > Debugging > Console+ (Experimental).

    Regex support didn't quite make it to the first version, but I'll keep that idea in mind for future updates ;)
     
    Singtaa likes this.
  17. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    I've made some good progress with the new Console+ window.
    If I'm going to have to write it all from scratch I might as well add some improvements on top :D

    console-plus.png

    (P.S. regex support for the search is now also included :cool:)
     
    Singtaa likes this.
  18. jasons-novaleaf

    jasons-novaleaf

    Joined:
    Sep 13, 2012
    Posts:
    181
    @SisusCo I tried adding this to a mostly empty project (just game objects) and get a lot of errors like:

    Library\PackageCache\com.unity.quicksearch@2.0.2\Editor\DebugTimer.cs(60,17): error CS0576: Namespace '<global namespace>' contains a definition conflicting with alias 'Debug'

    Library\PackageCache\com.unity.burst@1.4.1\Editor\BurstAotCompiler.cs(420,29): error CS0576: Namespace '<global namespace>' contains a definition conflicting with alias 'Debug'



    I'm using Unity 2020.2 let me know if you need more info.
     
  19. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    Hi @jasons-novaleaf

    The feature in Debug.Log Extensions that allows replacing the default Debug class across the project unfortunately does not work if any classes in the project contain the statement "using Debug = UnityEngine.Debug". Lately it seems more and more packages have been added to the package manager containing this statement and thus making it practically impossible to use this feature in many projects.

    So if you run into this conflict the only option currently is to not replace the Debug class globally by placing the extended Debug class in the global namespace, but to have it exist in a different namespace and then manually specify whenever you want to use it in your classes.

    You can move the Debug class back under a unique namespace by going to Edit > Project Settings... > Console and unticking the Replace Default Debug Class option.

    Replace Default Debug Class.png

    Because the project doesn't compile it is possible that the settings do not get applied automatically, in which case you can do it manually instead by double-clicking the package found at Assets > Sisus > Debug.Log Extensions > Installers > Install In Unique Namespace and selecting Import.

    Install In Unique Namespace.png

    (If after completing these steps you are still experiencing any issues you should do a clean install of Debug.Log Extensions.)


    After this change you will need to add "using Debug = Sisus.Debugging.Debug;" to any classes where you want to enable Debug.Log Extensions' enhancements.


    I hope this helps! I have done some experiments with alternative ways to replace the default debug class which could help resolve these compatibility issues. So maybe in a future update it can become possible to replace the Debug class globally in any project no matter what packages are being used.
     
    Last edited: Feb 4, 2021
  20. jasons-novaleaf

    jasons-novaleaf

    Joined:
    Sep 13, 2012
    Posts:
    181
    @SisusCo thank you for the reply. Unfortunately I can't do either workaround.

    The gui "console" setting in Project Settings does not exist. Also, the "Assets > Sisus > Debug.Log Extensions > Installers" folder does not exist.

    upload_2021-2-4_14-43-51.png

    curiously, I see that the installers folder is listed in the asset store "Package Contents" but for some reason it's not put into my project folder when I import it.


    PS: Thank you for explaining the problem.
     
  21. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    @jasons-novaleaf It looks like you might have an older version of Debug.Log Extensions installed.

    You should be able to update to the latest version by opening the package manager using the menu item Window > Package Manager, selecting the Debug.Log Extensions package and pressing the Update to 1.1.6 button and then importing it to the project.

    Updating-Package-Manager.png

    If you don't see the Console menu in Project Settings after updating to the latest version you can also disable the Use Global Namespace flag through the inspector by selecting the setting asset found at
    Assets > Sisus > Debug.Log Extensions > Resources > DebugLogExtensionsProjectSettings.

    DebugLogExtensionsProjectSettings.png
     
  22. jasons-novaleaf

    jasons-novaleaf

    Joined:
    Sep 13, 2012
    Posts:
    181
    Weird... this morning (about 2 hours ago) The update option didn't exist, but now it does. When I did that I got a prompt:
    upload_2021-2-4_18-20-25.png

    So I choose "No" and everything builds properly now. Thank you!
     
    SisusCo likes this.
  23. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    Glad to hear that you got everything working :)
     
  24. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    Version 1.1.8 of Debug.Log Extensions is now out and includes a number of new features:

    Debug.Log(int channel, ...):
    Added new methods that allow specifying the channel on which to log the message using a separate parameter instead of a string prefix. The channel options are generated based on the channels you've added in the project settings.
    Code (CSharp):
    1. public void Shoot()
    2. {
    3.     Debug.Log(Channel.Player, "Shooting a bullet.");
    4.  
    5.     SpawnBullet();
    6.     nextShotTime = Time.time + showSpanInterval;
    7. }
    debug-log-channel-output.PNG

    Debug.LogIf:
    Added new LogIf methods which function like Debug.Log but only log a message when a condition is true.
    Code (CSharp):
    1. public void PlayAudio(string fileName, Vector3 position)
    2. {
    3.     Dev.LogIf(debugEnabled, Channel.Audio, "PlayAudio(" + fileName + ") @ " + position);
    4.  
    5.     var clip = Resources.Load<AudioClip>("Audio/" + fileName);
    6.     AudioSource.PlayClipAtPoint(clip, position);
    7. }
    debug-logif-output.PNG

    Debug.Ensure:
    Added new Ensure methods that combine condition checks with error logging upon failure. They also make sure an error is only logged once per session to avoid flooding the log file.
    Code (CSharp):
    1. public void TransitionToScene(string sceneName)
    2. {
    3.     if(Debug.Ensure(!string.IsNullOrEmpty(sceneName))
    4.     {
    5.        TransitionToScene(SceneManager.GetSceneByName(sceneName));
    6.     }
    7. }
    debug-ensure-output.PNG

    Debug.Guard:
    Added new Guard methods which are just like the Ensure methods but their return value is reversed, making them more fitting for situations where you want to return early upon failure.
    Code (CSharp):
    1. public void TransitionToScene(string sceneName)
    2. {
    3.     if(Debug.Guard(!string.IsNullOrEmpty(sceneName), "Invalid sceneName"))
    4.     {
    5.         return;
    6.     }
    7.     TransitionToScene(SceneManager.GetSceneByName(sceneName));
    8. }
    debug-guard-output.PNG

    Find References
    The Console+ window now allows you to easily find all instances of any classes referenced in stack traces.
    find-references.png

    Also new in this version:
    • XML documentation is now included for most methods.
    • Stopwatches now always target the last started stopwatch when a name isn't specified.
    • New column options were added to the Console+ window (such as raw stack trace).
    • Added new context menu items to various Console+ window columns.
    • Console+ window can now be opened via a keyboard shortcut.
    • Added scrolling animations for new log entries to Console+ window.
    • Your personal channel now has the suffix "(Personal)" in the Console+ window channel dropdown menu to make it easier to identify.
    • Console+ window bug fixes.

    Happy debugging! ;)
     
    Last edited: Mar 29, 2021
    jasons-novaleaf likes this.
  25. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    Online documentation for Debug.Log Extensions is now available here.
     
  26. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    New features in Debug.Log Extensions 1.2.2:

    Monospace Font support
    (Requires Unity 2021.2 or newer)
    monospace-font-1-never.png
    monospace-font-2-details-only.png
    monospace-font-3-always.png

    Compact Mode

    compact-mode.png

    Enjoy!
     
  27. Gregor2211

    Gregor2211

    Joined:
    Aug 21, 2015
    Posts:
    2
    Hi @SisusCo
    I've just started using this tool and it looks pretty well!
    But I have a major problem with it: it doesn't work with Android builds for me.
    I have test script which logs in Update():

    UnityEngine.Debug.Log()
    Sisus.Debugging.Debug.Log()
    Sisus.Debugging.Dev.Log()
    Sisus.Debugging.DevCritical.Log()
    Sisus.Debugging.Critical.Log()

    and I see always only UnityEngine log entry. I use version without stripping log calls in builds.

    I've tried:
    - plug&play installation;
    - building DLL's in a fresh project that is set to Android as target build platform;
    - removing other versions of DLL's with setting last one for any platform including editor (without any defined constraints);
    - building with source scripts instead of DLL's;
    - building release and development builds;
    - building with&without SRDebugger, which I use for in-game console;

    When I make build for PC it works well and I can see logs. Of course everything works well in Editor.
    Tested on:
    Unity 2019.4.33f1
    Android 7 and 11
     
  28. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    Hi @Gregor2211

    Thank you for letting me know about this problem!

    The issue was that I had code that was trying to determine if "Use Player Log " was enabled in the Player Setting or not using essentially this code:
    File.Exists(Application.consoleLogPath)
    .

    As it turns out this
    Application.consoleLogPath
    seems to always just return an empty string on android devices...

    After getting rid of this step on mobile platforms logging started working on device as one would expect.

    android-build-test.png

    I'll start working on an update with this fix included and I'll let you know when it's ready.
     
  29. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    @Gregor2211 I sent you a PM with an updated version containing a fix for the logging issue in Android builds.

    I've also submitted the same update to the asset store so it should be available to download from there as well some time next week.
     
  30. Gregor2211

    Gregor2211

    Joined:
    Aug 21, 2015
    Posts:
    2
    Thank you very much, it works now :)
     
    SisusCo likes this.
  31. yoko-san

    yoko-san

    Joined:
    Jun 13, 2018
    Posts:
    4
    @SisusCo Hello!

    I like to store data in dictionaries, which contain lists or nested lists (for example Dictionary<int, List<Vector2Int>> or Dictionary<int, List<List<Vector2Int>>>).

    Is it possible to inspect the dictionary and the lists with your extension? :)
     
  32. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    Hello @yoko-san !

    While Debug.Log Extensions can handle logging nested lists/arrays, it can unfortunately only currently handle logging simple dictionaries though it's generic handling of the ICollection interface. It doesn't have special-case handling for KeyValuePair<TKey,TValue> at the moment so it just prints whatever the ToString() returns for each dictionary element.

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3. public class TestLogCollections : MonoBehaviour
    4. {
    5.     List<List<List<Vector2Int>>> listOfListOfList = new List<List<List<Vector2Int>>>()
    6.     {
    7.         { new List<List<Vector2Int>>() { new List<Vector2Int>() { new Vector2Int(1, 1) }  } },
    8.         { new List<List<Vector2Int>>() { new List<Vector2Int>() { new Vector2Int(2, 2) }  } }
    9.     };
    10.  
    11.     [ContextMenu("Test")]
    12.     public void Test()
    13.     {
    14.         Debug.Log(()=> listOfListOfList);
    15.     }
    16. }
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3. public class TestLogCollections : MonoBehaviour
    4. {
    5.     Dictionary<int, List<Vector2Int>> dictionary1 = new Dictionary<int, List<Vector2Int>>()
    6.     {
    7.         { 1, new List<Vector2Int>() { new Vector2Int(1, 1) }  },
    8.         { 2, new List<Vector2Int>() { new Vector2Int(2, 2) }  }
    9.     };
    10.  
    11.     Dictionary<int, List<List<Vector2Int>>> dictionary2 = new Dictionary<int, List<List<Vector2Int>>>()
    12.     {
    13.         { 1, new List<List<Vector2Int>>() { new List<Vector2Int>() { new Vector2Int(1, 1) }  } },
    14.         { 2, new List<List<Vector2Int>>() { new List<Vector2Int>() { new Vector2Int(2, 2) }  } }
    15.     };
    16.  
    17.     [ContextMenu("Test")]
    18.     public void Test()
    19.     {
    20.         Debug.Log(() => dictionary1);
    21.         Debug.Log(() => dictionary2);
    22.     }
    23. }

    Having better support for Dictionary is a superb idea though! I will add that in the next update.
     

    Attached Files:

  33. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    Now this is better...

    log-dictionary-update.png

    I'll try to put together an update during the weekend introducing better Dictionary support.
     
  34. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    Version 1.2.3 with improved collection value logging support has been submitted to the asset store for review. It should be live some time early next week.

    I also added the ability to customize the character that is added before and after collections in the preferences.

    log-collection.png
     
  35. yoko-san

    yoko-san

    Joined:
    Jun 13, 2018
    Posts:
    4
    @SisusCo Oh, wow, this looks very promising! :)

    Thank you for implementing this feature!
    I will definitely buy and test your asset in the next days ;)
     
    SisusCo likes this.
  36. Tom42_59

    Tom42_59

    Joined:
    Dec 16, 2019
    Posts:
    8
    I have been debugging some json strings and they have contained the character ‘[‘ and ‘]’. Is there any way to change the character used to set the channel or is there a way that once the channel is set, then any string that includes ‘[‘ or ‘]’ then it is ignored. I would prefer the latter if possible.
    (i am assuming your code is searching for the character ‘[‘ and ‘]’ and getting the value in between).

    Thanks, Tom
     
    Last edited: Feb 22, 2022
  37. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    @Tom42_59 Ah, I see what you mean :D

    log-json.png

    Every json string starts with
    [
    and ends with
    ]
    so the whole shebang gets interpreted as being a channel prefix.


    A couple of solutions to avoid this issue come to mind.
    1. All json strings start with
      ["
      , so I could ignore this as a channel prefix as a special rule. Or for a more generalized solution I could ignore all character sequence as a channel prefix starting with
      [
      where the second character isn't an alphanumeric character.
    2. I could skip interpreting message that end with
      ]
      as being channel prefixes. In other words there must be some text that follows a channel prefix or it'll get interpreted as being raw text.
    3. Allow disabling automatic on-the-fly channel generation entirely, only matching channel prefixes that are specifically added by the user in the Project Settings. Was this what you meant with your second suggestion?
    I'm thinking I should implement at least solutions #2 and #3. Possibly also #1 - but that might be unnecessary since it should probably also get covered by solution #2 in pretty much all cases.
     
    Tom42_59 likes this.
  38. Tom42_59

    Tom42_59

    Joined:
    Dec 16, 2019
    Posts:
    8
    Oooh, that does sound good. I think point 3 would be most beneficial and versatile for other uses that might come up. Any of these solutions would definitely be a great update for your asset.
     
    Last edited: Feb 23, 2022
    SisusCo likes this.
  39. Tom42_59

    Tom42_59

    Joined:
    Dec 16, 2019
    Posts:
    8
    Me again. I have just seen your update and have found things that may or may not work, depending on me not being stupid and using them incorrectly.

    • When making a new channel, after each letter you type, my mouse turns to the loading symbol and i think that creates a channel with what is currently in the text area with each letter i press, so when i have finished creating the channel, i have another 20 channels of "J", "JS", "JSO", "JSON" an so on. This was before the new update, i only just connected the dots.
    • The new feature that you added for ignoring unlisted channels, I may be using it completely wrong, but the toggle "Ignore Unlisted Channel Prefixes" doesn't change a thing for me, and i still get blank channels showing up on my channel list.
    • This is less of a bug, but more just me being impatient. Everytime i leave the UnityEditor for a few seconds and i enter back in, i am greeted with "Compiling C# scripts" or "Reloading script assemlies". I am not 100% sure that this Debug.Log extensions but it wasn't happening before i imported the asset.
    Sorry to be a pain again, Tom
     
    Last edited: Feb 26, 2022
  40. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    @Tom42_59 Hmm, thanks for letting me know about these issues. I must have introduced some sort of bug with the last update - I will look into it.
     
    Tom42_59 likes this.
  41. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    @Tom42_59
    I've fixed this in the update I just submitted for review, by delaying the changes made to the channels list to only get applied once the text field is no longer being edited.

    Have you tried resetting the channels list using the bottom option in the Channels dropdown?
    The Console+ window might just be remembering channels from messages logged during previous sessions.

    In my testing the toggle seems to be working at least:

    prefix-test.png

    I think this was happening due to the Channel class getting generated based on the channels added in the project settings. The class is only supposed to get rebuilt during reloading events if its contents don't match the channels configured in the project settings, but for some inexplicable reason the changes made to the file weren't always getting properly applied (something to do with Unity's asset database system?), resulting sometimes in the rebuilding and reimporting process getting repeated in vain multiple times o_O

    I changed this now so that the rebuilding only happens when a Rebuild Channel Class button is pressed in the Project Settings. This simpler solution seems to be working reliably in my testing with the changes getting applied every time.

    rebuild-channel-class.png
     

    Attached Files:

    Tom42_59 likes this.
  42. Tom42_59

    Tom42_59

    Joined:
    Dec 16, 2019
    Posts:
    8
    Sorry, i've been away from my computer all week. Works like a charm!
     
    SisusCo likes this.
  43. Tom42_59

    Tom42_59

    Joined:
    Dec 16, 2019
    Posts:
    8
    Sorry for the masses of small things i find, but here's another one:

    When pressing clear an there are errors in the console, the number of errors in the error count box (top left thing) goes to 0, even if there are errors.

    Without pressing clear:
    upload_2022-3-18_16-25-38.png


    With pressing clear:
    upload_2022-3-18_16-27-55.png
     
  44. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    @Tom42_59 Ah so the counter gets reset to zero even if there are still compile errors around. Thanks for reporting this! I'll start working on a fix.
     
    Tom42_59 likes this.
  45. Tom42_59

    Tom42_59

    Joined:
    Dec 16, 2019
    Posts:
    8
    It may also just be me, but using the
    Code (CSharp):
    1. Debug.Log(() => totalStepsFromAPIcall);
    statement, it works fine, but when using
    Code (CSharp):
    1. Debug.Log("[Channel 1]", () => totalStepsFromAPIcall);
    , it print the channel, but not the totalStepsFromAPIcall bit in this case.

    I am not sure if this is a bug or not, or if it is designed in this way.

    Sorry for all the posts I have been making, and thanks, Tom
     
  46. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    That would be a bug! Looks like it's using string.Format instead of string.Join to put together the final string by mistake. This is only supposed to happen when calling the Debug.LogFormat method.

    I'll fix this too in the next update - thanks for catching this one as well :)
     
    Tom42_59 likes this.
  47. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    @Tom42_59 Latest version of Debug.Log Extensions now has fixes for the compile error count clearing and
    Debug.Log("[Channel 1]", () => totalStepsFromAPIcall)
    issues.
     
    Tom42_59 likes this.
  48. dajnoo

    dajnoo

    Joined:
    Jun 9, 2018
    Posts:
    10
    Is there an option for displaying the time the log was created, the class name & line number for logs? In a build it would nice to see these things so we can check out what happened in the code.
     
  49. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    762
    @dajnoo There are unfortunately no such features built into Debug.Log Extensions :(

    You could create a pass-through method that adds this information to all messages though:
    Code (CSharp):
    1.  
    2. public static class Logger
    3. {
    4.     public static void Log(string message)
    5.     {
    6.         var stackFrame = new StackTrace().GetFrame(1);
    7.         var timeStamp = DateTime.Now.ToString("HH:mm:ss");
    8.         var classAndMethod = ExpressionUtility.ToString(stackFrame.GetMethod());
    9.         var lineNumber = stackFrame.GetFileLineNumber();
    10.         Debug.Log($"[{timeStamp}] {message}\n{classAndMethod}:{lineNumber}");
    11.     }
    12. }
    Test:
    Code (CSharp):
    1. public static class LoggerTest
    2. {
    3.     [MenuItem("Test/Logger test")]
    4.     private static void Test()
    5.     {
    6.         Logger.Log("Test");
    7.     }
    8. }
    additional-info.png
     
  50. yenmoc

    yenmoc

    Joined:
    Sep 21, 2019
    Posts:
    5
    Hi, are you planning to make it compatible with UPM?
     
unityunity