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