LogMatch.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Text.RegularExpressions;
  3. namespace UnityEngine.TestTools.Logging
  4. {
  5. [Serializable]
  6. internal class LogMatch
  7. {
  8. [SerializeField]
  9. private bool m_UseRegex;
  10. [SerializeField]
  11. private string m_Message;
  12. [SerializeField]
  13. private string m_MessageRegex;
  14. [SerializeField]
  15. private string m_LogType;
  16. public string Message
  17. {
  18. get { return m_Message; }
  19. set
  20. {
  21. m_Message = value;
  22. m_UseRegex = false;
  23. }
  24. }
  25. public Regex MessageRegex
  26. {
  27. get
  28. {
  29. if (!m_UseRegex)
  30. {
  31. return null;
  32. }
  33. return new Regex(m_MessageRegex);
  34. }
  35. set
  36. {
  37. if (value != null)
  38. {
  39. m_MessageRegex = value.ToString();
  40. m_UseRegex = true;
  41. }
  42. else
  43. {
  44. m_MessageRegex = null;
  45. m_UseRegex = false;
  46. }
  47. }
  48. }
  49. public LogType? LogType
  50. {
  51. get
  52. {
  53. if (!string.IsNullOrEmpty(m_LogType))
  54. {
  55. return Enum.Parse(typeof(LogType), m_LogType) as LogType ? ;
  56. }
  57. return null;
  58. }
  59. set
  60. {
  61. if (value != null)
  62. {
  63. m_LogType = value.Value.ToString();
  64. }
  65. else
  66. {
  67. m_LogType = null;
  68. }
  69. }
  70. }
  71. public bool Matches(LogEvent log)
  72. {
  73. if (LogType != null && LogType != log.LogType)
  74. {
  75. return false;
  76. }
  77. if (m_UseRegex)
  78. {
  79. return MessageRegex.IsMatch(log.Message);
  80. }
  81. else
  82. {
  83. return Message.Equals(log.Message);
  84. }
  85. }
  86. public override string ToString()
  87. {
  88. if (m_UseRegex)
  89. return string.Format("[{0}] Regex: {1}", LogType, MessageRegex);
  90. else
  91. return string.Format("[{0}] {1}", LogType, Message);
  92. }
  93. }
  94. }