LogKit.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /****************************************************************************
  2. * Copyright (c) 2017 snowcold
  3. * Copyright (c) 2017 ~ 2022 liangxie UNDER MIT License
  4. *
  5. * http://liangxiegame.com
  6. * https://github.com/liangxiegame/QFramework
  7. ****************************************************************************/
  8. namespace QFramework
  9. {
  10. using System;
  11. using UnityEngine;
  12. public enum LogLevel
  13. {
  14. None = 0,
  15. Exception = 1,
  16. Error = 2,
  17. Warning = 3,
  18. Normal = 4,
  19. Max = 5,
  20. }
  21. public static class Log
  22. {
  23. public static void LogInfo(this object selfMsg)
  24. {
  25. I(selfMsg);
  26. }
  27. public static void LogWarning(this object selfMsg)
  28. {
  29. W(selfMsg);
  30. }
  31. public static void LogError(this object selfMsg)
  32. {
  33. E(selfMsg);
  34. }
  35. public static void LogException(this Exception selfExp)
  36. {
  37. E(selfExp);
  38. }
  39. private static LogLevel mLogLevel = LogLevel.Normal;
  40. public static LogLevel Level
  41. {
  42. get { return mLogLevel; }
  43. set { mLogLevel = value; }
  44. }
  45. public static void I(object msg, params object[] args)
  46. {
  47. if (mLogLevel < LogLevel.Normal)
  48. {
  49. return;
  50. }
  51. if (args == null || args.Length == 0)
  52. {
  53. Debug.Log(msg);
  54. }
  55. else
  56. {
  57. Debug.LogFormat(msg.ToString(), args);
  58. }
  59. }
  60. public static void E(Exception e)
  61. {
  62. if (mLogLevel < LogLevel.Exception)
  63. {
  64. return;
  65. }
  66. Debug.LogException(e);
  67. }
  68. public static void E(object msg, params object[] args)
  69. {
  70. if (mLogLevel < LogLevel.Error)
  71. {
  72. return;
  73. }
  74. if (args == null || args.Length == 0)
  75. {
  76. Debug.LogError(msg);
  77. }
  78. else
  79. {
  80. Debug.LogError(string.Format(msg.ToString(), args));
  81. }
  82. }
  83. public static void W(object msg)
  84. {
  85. if (mLogLevel < LogLevel.Warning)
  86. {
  87. return;
  88. }
  89. Debug.LogWarning(msg);
  90. }
  91. public static void W(string msg, params object[] args)
  92. {
  93. if (mLogLevel < LogLevel.Warning)
  94. {
  95. return;
  96. }
  97. Debug.LogWarning(string.Format(msg, args));
  98. }
  99. }
  100. }