Jump to content

Disable logging


Adam Stepinski

Recommended Posts

I'm also interested in a solution to disable these logs.

And please no, filtering the logs is not a solution 🙂

FYI: In my case, the logs are only shown in the editor. I built an "in scene" log console in my app and the wave related logs are not showing up, when running on the Focus 3.

  • Like 1
Link to comment
Share on other sites

  • 8 months later...

same here. I am currently developing with cross-device
I'm getting tired of the many logs being printed when i not using Vive...

Is it possible to have an option to turn off the logs?

Link to comment
Share on other sites

  • 1 month later...

Good News!

A simple but effective solution is to override the default Unity's Debug.Log ILogHandler with your own.

Attach this script to a game object in the scene and adjust the keywords according to your needs 🙂

 

using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif

#if UNITY_EDITOR
    [InitializeOnLoad]
#endif
    public class LogHandlerManager : MonoBehaviour
    {
        private static string[] keywords ={
            "Wave",
            "Essense",
            "PackageInfo()", 
            "InteractionModeManagerSettings"
        };

        private static LogHandler logHandler; 

        static LogHandlerManager()
        {
            logHandler = new LogHandler();
            logHandler.keywords = keywords;
            
            Debug.unityLogger.logHandler = logHandler;
        }
    }

public class LogHandler : ILogHandler
{
    public string[] keywords;

    private static ILogHandler unityLogHandler = Debug.unityLogger.logHandler;

    public void LogException(Exception exception, UnityEngine.Object context)
    {
        unityLogHandler.LogException(exception, context);
    }

    public void LogFormat(LogType logType, UnityEngine.Object context, string format, params object[] args)
    {
        if (Application.isEditor)
        {
            foreach (string formatString in args)
            foreach (var keyword in keywords)
                if (formatString.Contains(keyword, StringComparison.OrdinalIgnoreCase))
                    return;
        }

        unityLogHandler.LogFormat(logType, context, format, args);
    }
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...