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