Log.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Diagnostics.CodeAnalysis;
  3. using JetBrains.Annotations;
  4. #if (UNITY_2019_4_OR_NEWER)
  5. using UnityEngine;
  6. #endif
  7. namespace SingularityGroup.HotReload {
  8. public static class Log {
  9. [SuppressMessage("ReSharper", "FieldCanBeMadeReadOnly.Global")]
  10. public static LogLevel minLevel = LogLevel.Info;
  11. /// <summary>
  12. /// Tag every log so that users know which logs came from Hot Reload
  13. /// </summary>
  14. private const string TAG = "[HotReload] ";
  15. public static void Debug(string message) {
  16. if (minLevel <= LogLevel.Debug) {
  17. #if (UNITY_2019_4_OR_NEWER)
  18. UnityEngine.Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, "{0}{1}", TAG, message);
  19. #else
  20. UnityEngine.Debug.Log(TAG + message);
  21. #endif
  22. }
  23. }
  24. [StringFormatMethod("message")]
  25. public static void Debug(string message, params object[] args) {
  26. if (minLevel <= LogLevel.Debug) {
  27. #if (UNITY_2019_4_OR_NEWER)
  28. UnityEngine.Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, TAG + message, args);
  29. #else
  30. UnityEngine.Debug.LogFormat(TAG + message, args);
  31. #endif
  32. }
  33. }
  34. public static void Info(string message) {
  35. if (minLevel <= LogLevel.Info) {
  36. #if (UNITY_2019_4_OR_NEWER)
  37. UnityEngine.Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, "{0}{1}", TAG, message);
  38. #else
  39. UnityEngine.Debug.Log(TAG + message);
  40. #endif
  41. }
  42. }
  43. [StringFormatMethod("message")]
  44. public static void Info(string message, params object[] args) {
  45. if (minLevel <= LogLevel.Info) {
  46. #if (UNITY_2019_4_OR_NEWER)
  47. UnityEngine.Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, TAG + message, args);
  48. #else
  49. UnityEngine.Debug.LogFormat(TAG + message, args);
  50. #endif
  51. }
  52. }
  53. public static void Warning(string message) {
  54. if (minLevel <= LogLevel.Warning) {
  55. #if (UNITY_2019_4_OR_NEWER)
  56. UnityEngine.Debug.LogFormat(LogType.Warning, LogOption.NoStacktrace, null, "{0}{1}", TAG, message);
  57. #else
  58. UnityEngine.Debug.LogWarning(TAG + message);
  59. #endif
  60. }
  61. }
  62. [StringFormatMethod("message")]
  63. public static void Warning(string message, params object[] args) {
  64. if (minLevel <= LogLevel.Warning) {
  65. #if (UNITY_2019_4_OR_NEWER)
  66. UnityEngine.Debug.LogFormat(LogType.Warning, LogOption.NoStacktrace, null, TAG + message, args);
  67. #else
  68. UnityEngine.Debug.LogWarningFormat(TAG + message, args);
  69. #endif
  70. }
  71. }
  72. public static void Error(string message) {
  73. if (minLevel <= LogLevel.Error) {
  74. #if (UNITY_2019_4_OR_NEWER)
  75. UnityEngine.Debug.LogFormat(LogType.Error, LogOption.NoStacktrace, null, "{0}{1}", TAG, message);
  76. #else
  77. UnityEngine.Debug.LogError(TAG + message);
  78. #endif
  79. }
  80. }
  81. [StringFormatMethod("message")]
  82. public static void Error(string message, params object[] args) {
  83. if (minLevel <= LogLevel.Error) {
  84. #if (UNITY_2019_4_OR_NEWER)
  85. UnityEngine.Debug.LogFormat(LogType.Error, LogOption.NoStacktrace, null, TAG + message, args);
  86. #else
  87. UnityEngine.Debug.LogErrorFormat(TAG + message, args);
  88. #endif
  89. }
  90. }
  91. public static void Exception(Exception exception) {
  92. if (minLevel <= LogLevel.Exception) {
  93. UnityEngine.Debug.LogException(exception);
  94. }
  95. }
  96. }
  97. }