Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. #include <regex.h>
  2. class ComponentX
  3. {
  4. public:
  5. ComponentX();
  6. virtual ~ComponentX() throw ();
  7. private:
  8. regex_t RegEx1;
  9. regex_t RegEx2;
  10. regex_t RegEx3;
  11. regex_t RegEx4;
  12. regex_t RegEx5;
  13. regex_t RegEx6;
  14. regex_t RegEx7;
  15. regex_t RegEx8;
  16. regex_t RegEx9;
  17. regex_t RegEx10;
  18. }
  19.  
  20. // Constructor
  21. ComponentX::ComponentX():
  22. {
  23. const char* Pattern1 = "^12";
  24. const char* Pattern2 = "REQUEST$";
  25. const char* Pattern3 = "^Key$";
  26. const char* Pattern4 = "client";
  27. const char* Pattern5 = "Fre*";
  28. const char* Pattern6 = "Buf{2,5}";
  29. const char* Pattern7 = "C(b|l)";
  30. const char* Pattern8 = "^.$";
  31. const char* Pattern9 = "E(b*|R*)R";
  32. const char* Pattern10 = "m.t";
  33.  
  34. regcomp(&RegEx1, Pattern1, 0);
  35. regcomp(&RegEx2, Pattern2, 0);
  36. regcomp(&RegEx3, Pattern3, 0);
  37. regcomp(&RegEx4, Pattern4, 0);
  38. regcomp(&RegEx5, Pattern5, 0);
  39. regcomp(&RegEx6, Pattern6, 0);
  40. regcomp(&RegEx7, Pattern7, 0);
  41. regcomp(&RegEx8, Pattern8, 0);
  42. regcomp(&RegEx9, Pattern9, 0);
  43. regcomp(&RegEx10, Pattern10, 0);
  44. }
  45.  
  46. // This method will be invoked continuously
  47. void ComponentX::LogReceived(int logserverSeq, const char* module, long sec, long usec, int pid, int level, int /* seq */, const char* msg)
  48. {
  49. char buf[BUFSIZE];
  50. struct tm* tm = ::localtime(&sec);
  51. const char* levelStr = "<unknown>";
  52.  
  53. bool bRegEx1 = false;
  54. bool bRegEx2 = false;
  55. bool bRegEx3 = false;
  56. bool bRegEx4 = false;
  57. bool bRegEx5 = false;
  58. bool bRegEx6 = false;
  59. bool bRegEx7 = false;
  60. bool bRegEx8 = false;
  61. bool bRegEx9 = false;
  62. bool bRegEx10 = false;
  63.  
  64. // Prepare the string
  65. const size_t count = ::snprintf(buf, BUFSIZE, "%d %s %d %02d:%02d:%02d.%03ld %s(%d) %s: %s: %s: %sn",logserverSeq,Months[tm->tm_mon],tm->tm_mday,tm->tm_hour,tm->tm_min, tm->tm_sec, usec / 1000, module, pid, levelStr,Product.c_str(),SerialNo.c_str(),msg);
  66.  
  67. // Check for all Regular expressions
  68. if (0 == regexec(&RegEx1, buf, 0, NULL, 0)) {
  69. bRegEx1 = true;
  70. }
  71. if (0 == regexec(&RegEx2, buf, 0, NULL, 0)) {
  72. bRegEx2 = true;
  73. }
  74. if (0 == regexec(&RegEx3, buf, 0, NULL, 0)) {
  75. bRegEx3 = true;
  76. }
  77. if (0 == regexec(&RegEx4, buf, 0, NULL, 0)) {
  78. bRegEx4 = true;
  79. }
  80. if (0 == regexec(&RegEx5, buf, 0, NULL, 0)) {
  81. bRegEx5 = true;
  82. }
  83. if (0 == regexec(&RegEx6, buf, 0, NULL, 0)) {
  84. bRegEx6 = true;
  85. }
  86. if (0 == regexec(&RegEx7, buf, 0, NULL, 0)) {
  87. bRegEx7 = true;
  88. }
  89. if (0 == regexec(&RegEx8, buf, 0, NULL, 0)) {
  90. bRegEx8 = true;
  91. }
  92. if (0 == regexec(&RegEx9, buf, 0, NULL, 0)) {
  93. bRegEx9 = true;
  94. }
  95. if (0 == regexec(&RegEx10, buf, 0, NULL, 0)) {
  96. bRegEx10 = true;
  97. }
  98.  
  99. // If any one RegEx is passed, notify the callback
  100. if (bRegEx1 == true || bRegEx2 == true || bRegEx3 == true || bRegEx4 == true ||bRegEx5 == true || bRegEx6 == true || bRegEx7 == true || bRegEx8 == true || bRegEx9 == true || bRegEx10 == true ) {
  101. if (count > 0) {
  102. for (auto i = Loggers.begin(); i != Loggers.end(); ++i) {
  103. (*i)->SendLog(buf, count);
  104. }
  105. }
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement