100 lines
3.0 KiB
C#
100 lines
3.0 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
#if UNITY_5_3_OR_NEWER
|
|
using UnityEngine;
|
|
#endif
|
|
|
|
namespace BITKit
|
|
{
|
|
public static class BIT4Log
|
|
{
|
|
#if UNITY_EDITOR && UNITY_5_3_OR_NEWER
|
|
[RuntimeInitializeOnLoadMethod]
|
|
private static void Reload()
|
|
{
|
|
OnLog = null;
|
|
OnException = null;
|
|
OnWarning = null;
|
|
OnNextLine = null;
|
|
}
|
|
#endif
|
|
public static event Action<string> OnLog;
|
|
public static event Action<Exception> OnException;
|
|
public static event Action<string> OnWarning;
|
|
public static event Action OnNextLine;
|
|
#if UNITY_5_3_OR_NEWER
|
|
[HideInCallstack]
|
|
#endif
|
|
public static void Log(object x)
|
|
{
|
|
if (OnLog is not null)
|
|
{
|
|
OnLog.Invoke(x?.ToString());
|
|
return;
|
|
}
|
|
#if UNITY_5_3_OR_NEWER
|
|
UnityEngine.Debug.Log(x);
|
|
#endif
|
|
}
|
|
#if UNITY_5_3_OR_NEWER
|
|
[HideInCallstack]
|
|
#endif
|
|
public static void Log<T>(object x)
|
|
{
|
|
if (OnLog is not null)
|
|
{
|
|
OnLog.Invoke(x?.ToString());
|
|
return;
|
|
}
|
|
#if UNITY_5_3_OR_NEWER
|
|
UnityEngine.Debug.Log($"<b>{typeof(T).Name}</b>" + x);
|
|
#endif
|
|
}
|
|
#if UNITY_5_3_OR_NEWER
|
|
[HideInCallstack]
|
|
#endif
|
|
public static void LogException(Exception e)
|
|
{
|
|
if (OnException is not null)
|
|
{
|
|
OnException.Invoke(e);
|
|
return;
|
|
}
|
|
#if UNITY_5_3_OR_NEWER
|
|
UnityEngine.Debug.LogException(e);
|
|
#endif
|
|
|
|
}
|
|
#if UNITY_5_3_OR_NEWER
|
|
[HideInCallstack]
|
|
#endif
|
|
public static void Warning(object x)
|
|
{
|
|
if (OnWarning is not null)
|
|
{
|
|
OnWarning.Invoke(x.ToString());
|
|
return;
|
|
}
|
|
#if UNITY_5_3_OR_NEWER
|
|
UnityEngine.Debug.LogWarning(x);
|
|
#endif
|
|
}
|
|
#if UNITY_5_3_OR_NEWER
|
|
[HideInCallstack]
|
|
#endif
|
|
public static void Warning<T>(object x)
|
|
{
|
|
if (OnWarning is not null)
|
|
{
|
|
OnWarning.Invoke(x.ToString());
|
|
return;
|
|
}
|
|
#if UNITY_5_3_OR_NEWER
|
|
UnityEngine.Debug.LogWarning($"<b>{typeof(T).Name}</b>" + x);
|
|
#endif
|
|
}
|
|
}
|
|
}
|