YooLogger.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System.Diagnostics;
  2. namespace YooAsset
  3. {
  4. /// <summary>
  5. /// 自定义日志处理
  6. /// </summary>
  7. public interface ILogger
  8. {
  9. void Log(string message);
  10. void Warning(string message);
  11. void Error(string message);
  12. void Exception(System.Exception exception);
  13. }
  14. internal static class YooLogger
  15. {
  16. public static ILogger Logger = null;
  17. /// <summary>
  18. /// 日志
  19. /// </summary>
  20. [Conditional("DEBUG")]
  21. public static void Log(string info)
  22. {
  23. if (Logger != null)
  24. {
  25. Logger.Log(info);
  26. }
  27. else
  28. {
  29. UnityEngine.Debug.Log(info);
  30. }
  31. }
  32. /// <summary>
  33. /// 警告
  34. /// </summary>
  35. public static void Warning(string info)
  36. {
  37. if (Logger != null)
  38. {
  39. Logger.Warning(info);
  40. }
  41. else
  42. {
  43. UnityEngine.Debug.LogWarning(info);
  44. }
  45. }
  46. /// <summary>
  47. /// 错误
  48. /// </summary>
  49. public static void Error(string info)
  50. {
  51. if (Logger != null)
  52. {
  53. Logger.Error(info);
  54. }
  55. else
  56. {
  57. UnityEngine.Debug.LogError(info);
  58. }
  59. }
  60. /// <summary>
  61. /// 异常
  62. /// </summary>
  63. public static void Exception(System.Exception exception)
  64. {
  65. if (Logger != null)
  66. {
  67. Logger.Exception(exception);
  68. }
  69. else
  70. {
  71. UnityEngine.Debug.LogException(exception);
  72. }
  73. }
  74. }
  75. }