Skip to content

Instantly share code, notes, and snippets.

@baruchadi
Last active February 12, 2024 12:30
Show Gist options
  • Save baruchadi/bd3c97a4aec273516a28684947a0184f to your computer and use it in GitHub Desktop.
Save baruchadi/bd3c97a4aec273516a28684947a0184f to your computer and use it in GitHub Desktop.
useful Debug.log extensions
using System;
using UnityEngine;
using Object = UnityEngine.Object;
namespace Utils
{
public static class DrowsyLogger
{
public static string Color(this string myStr, string color)
{
return $"<color={color}>{myStr}</color>";
}
private static void DoLog(Action<string, Object> LogFunction, string prefix, Object myObj, params object[] msg)
{
#if UNITY_EDITOR
var name = (myObj ? myObj.name : "NullObject").Color("lightblue");
LogFunction($"{prefix}[{name}]: {String.Join("; ", msg)}\n ", myObj);
#endif
}
public static void Log(this Object myObj, params object[] msg)
{
DoLog(Debug.Log, "", myObj, msg);
}
public static void LogError(this Object myObj, params object[] msg)
{
DoLog(Debug.LogError, "<!>".Color("red"), myObj, msg);
}
public static void LogWarning(this Object myObj, params object[] msg)
{
DoLog(Debug.LogWarning, "⚠️".Color("yellow"), myObj, msg);
}
public static void LogSuccess(this Object myObj, params object[] msg)
{
DoLog(Debug.Log, "".Color("green"), myObj, msg);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment