GothicVRProject / GothicVR

Fan project recreating the classic Gothic I and II experience in VR.
GNU General Public License v3.0
24 stars 2 forks source link

Introduce Debug.Log filter for development #309

Closed JaXt0r closed 2 months ago

JaXt0r commented 4 months ago

As more and more subsystems (like world loading, animation, etc.) benefit from logs, it clutters our Debug view. The goal is therefore to introduce a system where we filter unwanted logs during development (e.g. via FeatureFlags) and therefore focus on our logs of interest.

Idea: Debug.Log(Feature.WorldMesh, "some message");

This will be either logged or ignored based on settings at startup.

Implementation ideas:

JaXt0r commented 2 months ago

We can overwrite or extend the log functionality. Problem is, that we always get a misaligned Console view. image

  1. If we call an own log method and call the Unity logger afterwards, we get a totally misaligned Context (Console says, we didn't log on a class like Bootstrapper, but in a DebugLogHandler) --> If we click on it, we won't get the actual class, but the logger implementation.
public static void Log(string message, LogModule module)
        {
            if (!IsModuleEnabled(module))
                return;

            _gvrLogHandler.defaultLogHandler.LogFormat(LogType.Log, null, "[{0}] {1}", module, message);
        }
  1. If we just wrap Unity logging behaviour, we will get a similar outcome, but at least clicking on the Console will lead us to the log creating class.
public class GvrDebugLogHandler : ILogHandler
    {
        public ILogHandler defaultLogHandler;

        public GvrDebugLogHandler(ILogHandler defaultLogHandler)
        {
            this.defaultLogHandler = defaultLogHandler;
        }

        public void LogFormat(LogType logType, string message, GvrDebug.LogModule module)
        {
            message = string.Join("[", module , "] ", message);

            defaultLogHandler.LogFormat(logType, null, message, null);
        }
JaXt0r commented 2 months ago

As Unity uses its own console with the "click" and "display" magic, we would need to leverage some new console solution at all. e.g. https://github.com/bbbscarter/UberLogger image

JaXt0r commented 2 months ago

Therefore I recommend we are just cautious:

  1. If we have a one-time log message like "GVR bootstrapped" it's fine to have it
  2. If we have reoccurring messages, we should disable these logs via FeatureFlags and an IF-statement (or just remove the log entries from code if we don't need them any longer)

TL;DR: Let's do it as before. :-D