Search Unity

Question How to make a convoluted custom auto-log readable?

Discussion in 'Scripting' started by John_Leorid, May 20, 2022.

  1. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    For my next youtube video, I will release some source code, including a custom tool that's really cool and helps decoupling game-code. An Event System.
    And a really cool addition would be a Log.
    And by Log I mean a custom Editor Window that show "all" events when they happen.

    upload_2022-5-20_5-58-14.png

    Problem is that you get a few hundred entries in less than a second. And only ~5 of them are relevant.
    I tried adding a filter, so that you say "this won't be relevant" explicitly when creating an event in the system but it turns out that some events are relevant at one point in time and then stop being relevant.

    Also I limited the Log to 500 entries which is already a lot to scroll as you can see in the picture above. So it would be very cool to dismiss them once they are not needed anymore.

    Maybe I could collapse them by Subscriber? Giving each subscriber a limited number of events in the log?
    Obviously the user shouldn't care in his source code about logging, as this runs automatically.

    Has anyone had to deal with a convoluted automatic log yet? Did you manage to reduce the clutter? If so, how? ^^
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    Not sure how much value a general purpose logger would have... it's just a firehose of data.

    Generally when debugging you only care about one or two items, because ideally you strip your problem set down to just the items required to show the problem, then you debug it until you find the flaw, then remove the logging.
     
    John_Leorid likes this.
  3. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    The idea was a log that runs silently in the background and when something unexpected happens, you can open it and filter "by selection" or "by event name".

    Maybe I should just avoid the view where you can see every single message sent from any object to any other object.

    But the more I think about it, the more I think I should make it so, that you explicitly set which objects to log in advance - like you suggested - because then I can also log more detailed information without worrying about performance and I wouldn't have to restrain the maximum amount of Logs.
     
  4. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,999
    Years ago I once made a custom logging window which also showed all of the usual Debug.Log stuff besides custom log entries which could be any class with a certain interface which could even provide custom OnGUI code. So log entries could be interactive which was a really cool feature ^^. I didn't have a search or filter method. However the log was a "virtual scrollview" that only drew what is visible in the active area. So it could handle millions of entries. One feature I always missed in the normal Unity console was to delete single log entries and keep others. You could only clear the whole list. My log solution supported deleting single entries. I even had touch support as I was testing on Android at the time. It was in fact part of a larger debug framework I created. It even had a reflection based tiny version of an inspector as well as an independent free look camera in a seperate tab to inspect the scene. This even worked on an Androind tablet :) That was really fun.

    In-place filtering is kinda tricky. Filtering the whole log every frame is not possible or at least not a good idea. However if you setup a filter you could simply hold a filtered List in parallel. When you change the filter of course you have to parse the whole log to initialize the filtered list. However from now on you can simply let your logger filter any new entries as they come in. So new entries may be added to both lists at the same time if the filter passes.

    Though a virtual scroll view is pretty much a must have for logs. I mentioned that 10 years ago over here. It's really easy with a fix row height. However it gets tricky when you have variing heights for individual log entries.
     
    Kurt-Dekker likes this.