ProjectDDD/Assets/_Datas/SLShared/SLUnity/Editor/SLUnityLogger.cs
2025-06-17 20:47:57 +09:00

127 lines
4.2 KiB (Stored with Git LFS)
C#

using System.Diagnostics;
using System.Linq;
using Superlazy;
using UnityEngine;
using Debug = UnityEngine.Debug;
using Object = UnityEngine.Object;
public class SLUnityLogger : ISLLogger
{
private readonly string[] hideClasses = new string[] { "SLSystem", "SLGame", "SLEntity", "SLUnityLogger", "SLLog", "SLContainer", "SLValue" };
public string[] hideKeys = new string[0];
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]
private static void Load()
{
SLLog.Logger = new SLUnityLogger();
}
public void Info(string format, params object[] args)
{
var trace = new StackTrace(true);
var frames = trace.GetFrames();
var frame = frames.FirstOrDefault(f => hideClasses.Any(hc => f.GetMethod().DeclaringType.Name == hc) == false);
var fullText = $"[{frame.GetMethod().DeclaringType.Name}.{frame.GetMethod().Name}:{frame.GetFileLineNumber()}]{string.Format(format, args)}";
if (hideKeys.Where(k => fullText.Contains(k)).FirstOrDefault() != null) return;
#if UNITY_EDITOR
//UnityEditor.EditorUtility.DisplayDialog("Info", fullText, "확인", UnityEditor.DialogOptOutDecisionType.ForThisSession, "UnityLoggerDialog");
#endif
if (args.Length > 0 && args[0] is Object obj)
{
Debug.Log(fullText, obj);
}
else
{
Debug.Log(fullText);
}
}
public void Warn(string format, params object[] args)
{
var trace = new StackTrace(true);
var frames = trace.GetFrames();
var frame = frames.FirstOrDefault(f => hideClasses.Any(hc => f.GetMethod().DeclaringType.Name == hc) == false);
var fullText = $"[{frame.GetMethod().DeclaringType.Name}.{frame.GetMethod().Name}:{frame.GetFileLineNumber()}]{string.Format(format, args)}";
#if UNITY_EDITOR
UnityEditor.EditorUtility.DisplayDialog("Warn", fullText, "확인", UnityEditor.DialogOptOutDecisionType.ForThisSession, "UnityLoggerDialog");
#endif
if (args.Length > 0 && args[0] is Object obj)
{
Debug.LogWarning(fullText, obj);
}
else
{
Debug.LogWarning(fullText);
}
}
public void Error(string format, params object[] args)
{
var trace = new StackTrace(true);
var frames = trace.GetFrames();
var frame = frames.FirstOrDefault(f => hideClasses.Any(hc => f.GetMethod().DeclaringType.Name == hc) == false);
var fullText = $"[{frame.GetMethod().DeclaringType.Name}.{frame.GetMethod().Name}:{frame.GetFileLineNumber()}]{string.Format(format, args)}";
#if UNITY_EDITOR
UnityEditor.EditorUtility.DisplayDialog("Warn", fullText, "확인", UnityEditor.DialogOptOutDecisionType.ForThisSession, "UnityLoggerDialog");
#endif
if (args.Length > 0 && args[0] is Object obj)
{
Debug.LogError(fullText, obj);
}
else
{
Debug.LogError(fullText);
}
}
//private void OnUnityLog(string condition, string stackTrace, UnityEngine.LogType errorType, bool isThread)
//{
// string type = null;
// switch (errorType)
// {
// case LogType.Assert:
// type = "Debug";
// break;
// case LogType.Error:
// case LogType.Exception:
// type = "Error";
// break;
// case LogType.Log:
// type = "Log";
// break;
// case LogType.Warning:
// type = "Warn";
// break;
// }
// OnUnityLog(type, condition, stackTrace);
//}
// public void OnUnityLog(string type, string condition, string stackTrace)
// {
// if (type == "Error" && SLSystem.GetConfig("BuildTag").ToString().Contains("SL"))
// {
// NMGameSaver.SetOption("Debug", true);
// }
//#if !UNITY_EDITOR
// condition += "\n" + stackTrace;
//#endif
// if (filter[type])
// {
// logs.Add(new KeyValuePair<string, string>(type, condition));
// logScroll.y = float.MaxValue;
// filter["Session"] = false;
// }
// }
}