00001 #include "messagefacility/Utilities/ELseverityLevel.h"
00002
00003 #include "mfextensions/Receivers/qt_mf_msg.hh"
00004 #include "messagefacility/MessageService/ELdestination.h"
00005
00006 #include <iostream>
00007
00008 size_t qt_mf_msg::sequence = 0;
00009
00010 qt_mf_msg::qt_mf_msg(std::string hostname, std::string category, std::string application, pid_t pid, timeval time)
00011 : text_()
00012 , shortText_()
00013 , color_()
00014 , sev_(SERROR)
00015 , host_(QString(hostname.c_str()))
00016 , cat_(QString(category.c_str()))
00017 , app_(QString((application + " (" + std::to_string(pid) + ")").c_str()))
00018 , time_(time)
00019 , seq_(++sequence)
00020 , msg_("")
00021 , application_(QString(application.c_str()).toHtmlEscaped())
00022 , pid_(QString::number(pid))
00023 {
00024 }
00025
00026 void qt_mf_msg::setSeverity(mf::ELseverityLevel sev)
00027 {
00028 int sevid = sev.getLevel();
00029
00030 switch (sevid)
00031 {
00032 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00033 case mf::ELseverityLevel::ELsev_incidental:
00034 # endif
00035 case mf::ELseverityLevel::ELsev_success:
00036 case mf::ELseverityLevel::ELsev_zeroSeverity:
00037 case mf::ELseverityLevel::ELsev_unspecified:
00038 sev_ = SDEBUG;
00039 break;
00040
00041 case mf::ELseverityLevel::ELsev_info:
00042 sev_ = SINFO;
00043 break;
00044
00045 case mf::ELseverityLevel::ELsev_warning:
00046 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00047 case mf::ELseverityLevel::ELsev_warning2:
00048 # endif
00049 sev_ = SWARNING;
00050 break;
00051
00052 case mf::ELseverityLevel::ELsev_error:
00053 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00054 case mf::ELseverityLevel::ELsev_error2:
00055 case mf::ELseverityLevel::ELsev_next:
00056 case mf::ELseverityLevel::ELsev_severe2:
00057 case mf::ELseverityLevel::ELsev_abort:
00058 case mf::ELseverityLevel::ELsev_fatal:
00059 # endif
00060 case mf::ELseverityLevel::ELsev_severe:
00061 case mf::ELseverityLevel::ELsev_highestSeverity:
00062 sev_ = SERROR;
00063 break;
00064
00065 default: break;
00066 }
00067 }
00068
00069 void qt_mf_msg::setMessage(std::string prefix, int iteration, std::string msg)
00070 {
00071 sourceType_ = QString(prefix.c_str()).toHtmlEscaped();
00072 sourceSequence_ = iteration;
00073 msg_ = QString(msg.c_str()).toHtmlEscaped();
00074 }
00075
00076 void qt_mf_msg::updateText()
00077 {
00078 text_ = QString("<font color=");
00079
00080 QString sev_name = "Error";
00081 switch (sev_)
00082 {
00083 case SDEBUG:
00084 text_ += QString("#505050>");
00085 color_.setRgb(80, 80, 80);
00086 sev_name = "Debug";
00087 break;
00088
00089 case SINFO:
00090 text_ += QString("#008000>");
00091 color_.setRgb(0, 128, 0);
00092 sev_name = "Info";
00093 break;
00094
00095 case SWARNING:
00096 text_ += QString("#E08000>");
00097 color_.setRgb(224, 128, 0);
00098 sev_name = "Warning";
00099 break;
00100
00101 case SERROR:
00102 text_ += QString("#FF0000>");
00103 color_.setRgb(255, 0, 0);
00104 sev_name = "Error";
00105 break;
00106
00107 default: break;
00108 }
00109
00110 shortText_ = QString(text_);
00111 shortText_ += QString("<pre style=\"margin-top: 0; margin-bottom: 0;\">");
00112 shortText_ += msg_;
00113 shortText_ += QString("</pre></font>");
00114
00115
00116 size_t constexpr SIZE{ 144 };
00117 struct tm timebuf;
00118 char ts[SIZE];
00119 strftime(ts, sizeof(ts), "%d-%b-%Y %H:%M:%S %Z", localtime_r(&time_.tv_sec, &timebuf));
00120
00121
00122 text_ += QString("<pre style=\"width: 100%;\">")
00123 + sev_name.toHtmlEscaped() + " / "
00124 + cat_.toHtmlEscaped() + "<br>"
00125 + QString(ts).toHtmlEscaped() + "<br>"
00126 + host_.toHtmlEscaped() + " ("
00127 + hostaddr_ + ")<br>"
00128 + sourceType_ + " " + QString::number(sourceSequence_) + " / "
00129 + "PID " + pid_;
00130
00131 if (file_ != "")
00132 text_ += QString(" / ") + file_ + QString(":") + line_;
00133
00134 text_ += QString("<br>")
00135 + application_ + " / "
00136 + module_ + " / "
00137 + eventID_ + "<br>"
00138 + msg_
00139 + QString("</pre>");
00140
00141 text_ += QString("</font>");
00142
00143 }