Setup conditional debugging system in Unity3d

What i wish to achieve

  1. Allowing to disable selected types of debug in different levels

    Such as
    DEBUG_LEVEL_LOG
    DEBUG_LEVEL_WARN
    DEBUG_LEVEL_ERROR

  2. Setup different types of the debug messages
    Debug.log
    Debug.error
    Debug.warning

  3. Setup the title of debug that helps to search later

    Debug.Log("searchName" + "debug message here");

In order to achieve this, we create a class named: D

We will define the search name and the Debug levels by #define

Now we can simply comment out the top #defines to disable the type of logging here in one place.

#define DEBUG_LEVEL_LOG
#define DEBUG_LEVEL_WARN
#define DEBUG_LEVEL_ERROR

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class D 
{
    static string searchName = "DM: ";
    static bool DEBUG_LEVEL_LOG = true;

    public static void log(string format, params object[] paramList)
    {
#if DEBUG_LEVEL_LOG
        Debug.Log(searchName + string.Format(format, paramList));
#endif
    }

    public static void warn(string format, params object[] paramList)
    {
#if DEBUG_LEVEL_WARN 
        Debug.LogWarning(searchName + string.Format(format, paramList));
#endif
    }

    public static void err(string format, params object[] paramList)
    {
#if DEBUG_LEVEL_ERROR
        Debug.LogError(searchName + string.Format(format, paramList));
#endif
    }

}

To use the debug setup as follows:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class testDebug : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        D.log("What is the problem?");
        D.warn("Jialat");
        D.err("problem liao");

    }

    // Update is called once per frame
    void Update()
    {
        
    }
}