artdaq_mfextensions  v1_03_01
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 void qt_mf_msg::setSeverity(mf::ELseverityLevel sev)
26 {
27  int sevid = sev.getLevel();
28 
29  switch (sevid)
30  {
31  case mf::ELseverityLevel::ELsev_success:
32  case mf::ELseverityLevel::ELsev_zeroSeverity:
33  case mf::ELseverityLevel::ELsev_unspecified:
34  sev_ = SDEBUG;
35  break;
36 
37  case mf::ELseverityLevel::ELsev_info:
38  sev_ = SINFO;
39  break;
40 
41  case mf::ELseverityLevel::ELsev_warning:
42  sev_ = SWARNING;
43  break;
44 
45  case mf::ELseverityLevel::ELsev_error:
46  case mf::ELseverityLevel::ELsev_severe:
47  case mf::ELseverityLevel::ELsev_highestSeverity:
48  sev_ = SERROR;
49  break;
50 
51  default: break;
52  }
53 }
54 
55 void qt_mf_msg::setMessage(std::string prefix, int iteration, std::string msg)
56 {
57  sourceType_ = QString(prefix.c_str()).toHtmlEscaped();
58  sourceSequence_ = iteration;
59  msg_ = QString(msg.c_str()).toHtmlEscaped();
60 }
61 
62 void qt_mf_msg::updateText()
63 {
64  text_ = QString("<font color=");
65 
66  QString sev_name = "Error";
67  switch (sev_)
68  {
69  case SDEBUG:
70  text_ += QString("#505050>");
71  color_.setRgb(80, 80, 80);
72  sev_name = "Debug";
73  break;
74 
75  case SINFO:
76  text_ += QString("#008000>");
77  color_.setRgb(0, 128, 0);
78  sev_name = "Info";
79  break;
80 
81  case SWARNING:
82  text_ += QString("#E08000>");
83  color_.setRgb(224, 128, 0);
84  sev_name = "Warning";
85  break;
86 
87  case SERROR:
88  text_ += QString("#FF0000>");
89  color_.setRgb(255, 0, 0);
90  sev_name = "Error";
91  break;
92 
93  default: break;
94  }
95 
96  shortText_ = QString(text_);
97  shortText_ += QString("<pre style=\"margin-top: 0; margin-bottom: 0;\">");
98  shortText_ += msg_;
99  shortText_ += QString("</pre></font>");
100 
101 
102  size_t constexpr SIZE{ 144 };
103  struct tm timebuf;
104  char ts[SIZE];
105  strftime(ts, sizeof(ts), "%d-%b-%Y %H:%M:%S %Z", localtime_r(&time_.tv_sec, &timebuf));
106 
107 
108  text_ += QString("<pre style=\"width: 100%;\">")
109  + sev_name.toHtmlEscaped() + " / "
110  + cat_.toHtmlEscaped() + "<br>"
111  + QString(ts).toHtmlEscaped() + "<br>"
112  + host_.toHtmlEscaped() + " ("
113  + hostaddr_ + ")<br>"
114  + sourceType_ + " " + QString::number(sourceSequence_) + " / "
115  + "PID " + pid_;
116 
117  if (file_ != "")
118  text_ += QString(" / ") + file_ + QString(":") + line_;
119 
120  text_ += QString("<br>")
121  + application_ + " / "
122  + module_ + " / "
123  + eventID_ + "<br>"
124  + msg_ // + "<br>"
125  + QString("</pre>");
126 
127  text_ += QString("</font>");
128 
129 }
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