Merge pull request #72 from HXiaoMing/feat-custom-logger

feat(YooLogger):支持自定义日志处理,方便收集线上问题
pull/82/head
何冠峰 2023-03-03 18:03:21 +08:00 committed by GitHub
commit ef13e19c48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 4 deletions

View File

@ -2,39 +2,83 @@
namespace YooAsset 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 internal static class YooLogger
{ {
/// <summary>
/// 自定义日志处理
/// </summary>
public static IYooLogger Logger = null;
/// <summary> /// <summary>
/// 日志 /// 日志
/// </summary> /// </summary>
[Conditional("DEBUG")] [Conditional("DEBUG")]
public static void Log(string info) public static void Log(string info)
{
if (Logger != null)
{
Logger.Info(info);
}
else
{ {
UnityEngine.Debug.Log(info); UnityEngine.Debug.Log(info);
} }
}
/// <summary> /// <summary>
/// 警告 /// 警告
/// </summary> /// </summary>
public static void Warning(string info) public static void Warning(string info)
{
if (Logger != null)
{
Logger.Warning(info);
}
else
{ {
UnityEngine.Debug.LogWarning(info); UnityEngine.Debug.LogWarning(info);
} }
}
/// <summary> /// <summary>
/// 错误 /// 错误
/// </summary> /// </summary>
public static void Error(string info) public static void Error(string info)
{
if (Logger != null)
{
Logger.Error(info);
}
else
{ {
UnityEngine.Debug.LogError(info); UnityEngine.Debug.LogError(info);
} }
}
/// <summary> /// <summary>
/// 异常 /// 异常
/// </summary> /// </summary>
public static void Exception(System.Exception exception) public static void Exception(System.Exception exception)
{
if (Logger != null)
{
Logger.Exception(exception);
}
else
{ {
UnityEngine.Debug.LogException(exception); UnityEngine.Debug.LogException(exception);
} }
} }
}
} }

View File

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