UniVRM/Assets/UniGLTF/Runtime/Utils/UniGLTFLogger.cs

58 lines
1.9 KiB
C#

using UnityEngine;
namespace UniGLTF
{
public static class UniGLTFLogger
{
class DefaultUnityLogger : ILogHandler
{
public void LogException(System.Exception exception, UnityEngine.Object context)
{
Debug.LogException(exception, context);
}
public void LogFormat(LogType logType, UnityEngine.Object context, string format, params object[] args)
{
switch (logType)
{
case LogType.Error:
Debug.LogError(string.Format(format, args), context);
break;
case LogType.Assert:
Debug.LogAssertion(string.Format(format, args), context);
break;
case LogType.Warning:
Debug.LogWarning(string.Format(format, args), context);
break;
case LogType.Log:
Debug.Log(string.Format(format, args), context);
break;
case LogType.Exception:
// where exception ?
Debug.LogError(string.Format(format, args), context);
break;
default:
throw new System.NotImplementedException();
}
}
}
static ILogHandler s_logger = new DefaultUnityLogger();
public static void SetLogger(ILogHandler logger)
{
if (logger != null)
{
s_logger = logger;
}
else
{
s_logger = new DefaultUnityLogger();
}
}
[System.Diagnostics.Conditional("VRM_DEVELOP")]
[HideInCallstack]
public static void Log(string msg, UnityEngine.Object context = null) => s_logger.LogFormat(LogType.Log, context, msg);
}
}