feat(YooLogger):支持自定义日志处理,方便收集线上问题

pull/72/head
huanggongming 2023-03-01 16:10:24 +08:00
parent 4f0f0e54ac
commit 69125e967f
2 changed files with 57 additions and 4 deletions

View File

@ -2,15 +2,38 @@
namespace YooAsset
{
public abstract class IYooLogger
{
public abstract void Info(string msg);
public abstract void Warning(string msg);
public abstract void Error(string msg);
public abstract void Exception(System.Exception exception);
}
internal static class YooLogger
{
/// <summary>
/// 自定义日志处理
/// </summary>
public static IYooLogger Logger = null;
/// <summary>
/// 日志
/// </summary>
[Conditional("DEBUG")]
public static void Log(string info)
{
UnityEngine.Debug.Log(info);
if (Logger != null)
{
Logger.Info(info);
}
else
{
UnityEngine.Debug.Log(info);
}
}
/// <summary>
@ -18,7 +41,14 @@ namespace YooAsset
/// </summary>
public static void Warning(string info)
{
UnityEngine.Debug.LogWarning(info);
if (Logger != null)
{
Logger.Warning(info);
}
else
{
UnityEngine.Debug.LogWarning(info);
}
}
/// <summary>
@ -26,7 +56,14 @@ namespace YooAsset
/// </summary>
public static void Error(string info)
{
UnityEngine.Debug.LogError(info);
if (Logger != null)
{
Logger.Error(info);
}
else
{
UnityEngine.Debug.LogError(info);
}
}
/// <summary>
@ -34,7 +71,14 @@ namespace YooAsset
/// </summary>
public static void Exception(System.Exception exception)
{
UnityEngine.Debug.LogException(exception);
if (Logger != null)
{
Logger.Exception(exception);
}
else
{
UnityEngine.Debug.LogException(exception);
}
}
}
}

View File

@ -184,6 +184,15 @@ namespace YooAsset
DownloadSystem.CertificateHandlerInstance = instance;
}
/// <summary>
/// 自定义日志处理
/// </summary>
/// <param name="logger"></param>
public static void SetLogger(IYooLogger logger)
{
YooLogger.Logger = logger;
}
/// <summary>
/// 设置下载系统参数,自定义下载请求
/// </summary>