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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How can I delete a message from unity's debug logger?

Discussion in 'Scripting' started by Rick-Gamez, Jan 24, 2018.

  1. Rick-Gamez

    Rick-Gamez

    Joined:
    Mar 23, 2015
    Posts:
    218
    Hey everyone, I'm trying to create a message filter for unity's log so that I can filter and remove specific messages from it.

    I have tried to use Debug.unityLogger.filterLogType but, I can't seem to get the message to go away.

    I also found an old thread that showed how to override unity's Debug class but that can't work because Unity has since sealed the Debug class.

    The only other idea that I have come up with is to remove messages from the log list manually based on the message text but I'm not sure how this can be done. Does anyone know?

    FYI : The message that I'm trying to filter specifically is the "GUI Getting Control's Position" message just in case there's another way to stop that from logging... (wish this was an actual exception...BTW)

    Any ideas? Thanks.
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,199
    You could use reflection to replace UnityEngine.Debug.s_logger, which is what handles all the log messages internally. Then you simply pass the messages you want to care about on to the default logger.
     
  3. Rick-Gamez

    Rick-Gamez

    Joined:
    Mar 23, 2015
    Posts:
    218
    Thanks! I haven't tried it yet because this led me to discover that unity's Logger class is not sealed... Now I'm going to get crazy with it by requiring the constructor of my Logger class to take in some filter interface or something of that sort that can take a message and return a bool on weather or not the msg is filtered... So that my logger will know how to handle any filter I come up with. Thanks again, I'll let you know how it works.

    It would be easy to implement my interface to my editor windows then the logger can ask the window's instance.
     
  4. Rick-Gamez

    Rick-Gamez

    Joined:
    Mar 23, 2015
    Posts:
    218
    Okay I am able to block everything but this message LOL so it must be logged in a different way than standard messages.
     
    SolidAlloy likes this.
  5. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,209
    Any tips/code on how to do this? There are some really annoying and pointless logs on my headless server I would love to intercept. I'm not versed in reflection =3

    edit: I was able to override every method in Debug, but it still didn't stop garbage collection logs from spamming my log =[ which is my real goal for my headless server.
     
    Last edited: Dec 7, 2019
    SolidAlloy likes this.
  6. SolidAlloy

    SolidAlloy

    Joined:
    Oct 21, 2019
    Posts:
    58
    I stumbled upon this too. In my case, I wanted to get rid of the "No script asset for..." warning. Warnings like this get printed by C++ backend, and it doesn't give a s*** about unityLogger.enabled or unityLogger.filterLogType. They really need to either replace such logs with exceptions or allow disabling them. At one point, I seem to have found the solution by calling Debug.RemoveLogEntriesByIdentifier() through Reflection - but nope, this method clears all the logs just like LogEntries.Clear(). So we have no way to remove specific messages even through Reflection.
     
    malkere likes this.
  7. SolidAlloy

    SolidAlloy

    Joined:
    Oct 21, 2019
    Posts:
    58
    I found a way to delete at least some editor-generated logs. There is an internal method
    UnityEditor.LogEntry.RemoveLogEntriesByMode(int mode)
    that can be called through reflection.

    The integer passed to the method is a C++-side enum that contains different log modes. Here are some values I found:
    0 -- All the user-generated logs (info, warning, error, etc.)
    2 -- Errors reported by the editor (I was able to remove the "... is missing the class attribute 'ExtensionOfNativeClass'" error with help of it but I'm not sure it removes all the editor-reported errors.)
    256 -- User-generated errors, exceptions, etc.
    512 -- all warnings (user-generated and *logged by the editor itself*).
    262144 -- A specific mode that removes only the "No script asset for ..." warning for me. Not sure if it removes any other warning reported by Unity (it didn't remove any other log entry on my end).
    8406016 --- User-generated info message.
    8405504 --- User-logged warning message.

    Hope it helps someone.
     
    Last edited: Sep 6, 2022