ATLogger.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using UnityEngine;
  3. namespace AnyThinkAds.Common
  4. {
  5. public class ATLogger
  6. {
  7. private static bool isDebug = false;
  8. public static bool IsDebug
  9. {
  10. get {
  11. return isDebug;
  12. }
  13. set {
  14. isDebug = value;
  15. }
  16. }
  17. // public static void Log(string msg)
  18. // {
  19. // Log(msg, null);
  20. // }
  21. // public static void Log(string format, object obj)
  22. // {
  23. // Log(format, obj, null);
  24. // }
  25. public static void Log(string format, object obj1 = null, object obj2 = null)
  26. {
  27. if (!isDebug) {
  28. return;
  29. }
  30. try {
  31. if (obj1 == null && obj2 == null)
  32. {
  33. Debug.Log(format);
  34. }
  35. else if (obj1 != null && obj2 == null)
  36. {
  37. Debug.Log(String.Format(format, obj1));
  38. }
  39. else if (obj1 == null && obj2 != null)
  40. {
  41. Debug.Log(String.Format(format, obj2));
  42. }
  43. else {
  44. Debug.Log(String.Format(format, obj1, obj2));
  45. }
  46. } catch(Exception e)
  47. {
  48. Debug.LogError("Log error: " + e.Message);
  49. }
  50. }
  51. // public static void LogError(string msg)
  52. // {
  53. // LogError(msg, null);
  54. // }
  55. // public static void LogError(string format, object obj)
  56. // {
  57. // LogError(format, obj, null);
  58. // }
  59. public static void LogError(string format, object obj1 = null, object obj2 = null)
  60. {
  61. if (!isDebug) {
  62. return;
  63. }
  64. try {
  65. if (obj1 == null && obj2 == null)
  66. {
  67. Debug.LogError(format);
  68. }
  69. else if (obj1 != null && obj2 == null)
  70. {
  71. Debug.LogError(String.Format(format, obj1));
  72. }
  73. else if (obj1 == null && obj2 != null)
  74. {
  75. Debug.LogError(String.Format(format, obj2));
  76. }
  77. else {
  78. Debug.LogError(String.Format(format, obj1, obj2));
  79. }
  80. } catch(Exception e)
  81. {
  82. Debug.LogError("Log error: " + e.Message);
  83. }
  84. }
  85. }
  86. }