artdaq_mfextensions  v1_03_00
qt_mf_msg.cc
1 #include "messagefacility/Utilities/ELseverityLevel.h"
2 
3 #include "mfextensions/Receivers/qt_mf_msg.hh"
4 #include "messagefacility/MessageService/ELdestination.h"
5 //#include "mfextensions/Extensions/MFExtensions.hh"
6 #include <iostream>
7 
8 size_t qt_mf_msg::sequence = 0;
9 
10 qt_mf_msg::qt_mf_msg(std::string hostname, std::string category, std::string application, pid_t pid, timeval time)
11  : text_()
12  , shortText_()
13  , color_()
14  , sev_(SERROR)
15  , host_(QString(hostname.c_str()))
16  , cat_(QString(category.c_str()))
17  , app_(QString((application + " (" + std::to_string(pid) + ")").c_str()))
18  , time_(time)
19  , seq_(++sequence)
20  , msg_("")
21  , application_(QString(application.c_str()).toHtmlEscaped())
22  , pid_(QString::number(pid))
23 {
24 }
25 
26 void qt_mf_msg::setSeverity(mf::ELseverityLevel sev)
27 {
28  int sevid = sev.getLevel();
29 
30  switch (sevid)
31  {
32 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
33  case mf::ELseverityLevel::ELsev_incidental:
34 # endif
35  case mf::ELseverityLevel::ELsev_success:
36  case mf::ELseverityLevel::ELsev_zeroSeverity:
37  case mf::ELseverityLevel::ELsev_unspecified:
38  sev_ = SDEBUG;
39  break;
40 
41  case mf::ELseverityLevel::ELsev_info:
42  sev_ = SINFO;
43  break;
44 
45  case mf::ELseverityLevel::ELsev_warning:
46 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
47  case mf::ELseverityLevel::ELsev_warning2:
48 # endif
49  sev_ = SWARNING;
50  break;
51 
52  case mf::ELseverityLevel::ELsev_error:
53 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
54  case mf::ELseverityLevel::ELsev_error2:
55  case mf::ELseverityLevel::ELsev_next:
56  case mf::ELseverityLevel::ELsev_severe2:
57  case mf::ELseverityLevel::ELsev_abort:
58  case mf::ELseverityLevel::ELsev_fatal:
59 # endif
60  case mf::ELseverityLevel::ELsev_severe:
61  case mf::ELseverityLevel::ELsev_highestSeverity:
62  sev_ = SERROR;
63  break;
64 
65  default: break;
66  }
67 }
68 
69 void qt_mf_msg::setMessage(std::string prefix, int iteration, std::string msg)
70 {
71  sourceType_ = QString(prefix.c_str()).toHtmlEscaped();
72  sourceSequence_ = iteration;
73  msg_ = QString(msg.c_str()).toHtmlEscaped();
74 }
75 
76 void qt_mf_msg::updateText()
77 {
78  text_ = QString("<font color=");
79 
80  QString sev_name = "Error";
81  switch (sev_)
82  {
83  case SDEBUG:
84  text_ += QString("#505050>");
85  color_.setRgb(80, 80, 80);
86  sev_name = "Debug";
87  break;
88 
89  case SINFO:
90  text_ += QString("#008000>");
91  color_.setRgb(0, 128, 0);
92  sev_name = "Info";
93  break;
94 
95  case SWARNING:
96  text_ += QString("#E08000>");
97  color_.setRgb(224, 128, 0);
98  sev_name = "Warning";
99  break;
100 
101  case SERROR:
102  text_ += QString("#FF0000>");
103  color_.setRgb(255, 0, 0);
104  sev_name = "Error";
105  break;
106 
107  default: break;
108  }
109 
110  shortText_ = QString(text_);
111  shortText_ += QString("<pre style=\"margin-top: 0; margin-bottom: 0;\">");
112  shortText_ += msg_;
113  shortText_ += QString("</pre></font>");
114 
115 
116  size_t constexpr SIZE{ 144 };
117  struct tm timebuf;
118  char ts[SIZE];
119  strftime(ts, sizeof(ts), "%d-%b-%Y %H:%M:%S %Z", localtime_r(&time_.tv_sec, &timebuf));
120 
121 
122  text_ += QString("<pre style=\"width: 100%;\">")
123  + sev_name.toHtmlEscaped() + " / "
124  + cat_.toHtmlEscaped() + "<br>"
125  + QString(ts).toHtmlEscaped() + "<br>"
126  + host_.toHtmlEscaped() + " ("
127  + hostaddr_ + ")<br>"
128  + sourceType_ + " " + QString::number(sourceSequence_) + " / "
129  + "PID " + pid_;
130 
131  if (file_ != "")
132  text_ += QString(" / ") + file_ + QString(":") + line_;
133 
134  text_ += QString("<br>")
135  + application_ + " / "
136  + module_ + " / "
137  + eventID_ + "<br>"
138  + msg_ // + "<br>"
139  + QString("</pre>");
140 
141  text_ += QString("</font>");
142 
143 }
qt_mf_msg(std::string hostname, std::string category, std::string application, pid_t pid, timeval time)
Construct a qt_mf_msg
Definition: qt_mf_msg.cc:10