UnityLogger.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Text.RegularExpressions;
  3. namespace ET
  4. {
  5. public class UnityLogger: ILog
  6. {
  7. public void Trace(string msg)
  8. {
  9. UnityEngine.Debug.Log(msg);
  10. }
  11. public void Debug(string msg)
  12. {
  13. UnityEngine.Debug.Log(msg);
  14. }
  15. public void Info(string msg)
  16. {
  17. UnityEngine.Debug.Log(msg);
  18. }
  19. public void Warning(string msg)
  20. {
  21. UnityEngine.Debug.LogWarning(msg);
  22. }
  23. public void Error(string msg)
  24. {
  25. #if UNITY_EDITOR
  26. msg = Msg2LinkStackMsg(msg);
  27. #endif
  28. UnityEngine.Debug.LogError(msg);
  29. }
  30. private static string Msg2LinkStackMsg(string msg)
  31. {
  32. msg = Regex.Replace(msg,@"at (.*?) in (.*?\.cs):(\w+)", match =>
  33. {
  34. string path = match.Groups[2].Value;
  35. string line = match.Groups[3].Value;
  36. return $"{match.Groups[1].Value}\n<a href=\"{path}\" line=\"{line}\">{path}:{line}</a>";
  37. });
  38. return msg;
  39. }
  40. public void Error(Exception e)
  41. {
  42. UnityEngine.Debug.LogException(e);
  43. }
  44. public void Trace(string message, params object[] args)
  45. {
  46. UnityEngine.Debug.LogFormat(message, args);
  47. }
  48. public void Warning(string message, params object[] args)
  49. {
  50. UnityEngine.Debug.LogWarningFormat(message, args);
  51. }
  52. public void Info(string message, params object[] args)
  53. {
  54. UnityEngine.Debug.LogFormat(message, args);
  55. }
  56. public void Debug(string message, params object[] args)
  57. {
  58. UnityEngine.Debug.LogFormat(message, args);
  59. }
  60. public void Error(string message, params object[] args)
  61. {
  62. UnityEngine.Debug.LogErrorFormat(message, args);
  63. }
  64. }
  65. }