00001 #include "messagefacility/Utilities/MessageFacilityMsg.h"
00002 #include "messagefacility/Utilities/ELseverityLevel.h"
00003
00004 #include "mfextensions/Binaries/qt_mf_msg.hh"
00005
00006 #include <iostream>
00007
00008 size_t qt_mf_msg::sequence = 0;
00009
00010 qt_mf_msg::qt_mf_msg(mf::MessageFacilityMsg const& msg)
00011 : text_()
00012 , shortText_()
00013 , color_()
00014 , sev_()
00015 , host_(QString(msg.hostname().substr(0, msg.hostname().find_first_of('.')).c_str()))
00016 , cat_(QString(msg.category().c_str()))
00017 , app_(QString((msg.application() + " (" + std::to_string(msg.pid()) + ")").c_str()))
00018 , time_(msg.timestamp())
00019 , seq_(++sequence)
00020 {
00021 mf::ELseverityLevel severity(msg.severity());
00022 int sevid = severity.getLevel();
00023
00024 text_ = QString("<font color=");
00025
00026 switch (sevid)
00027 {
00028 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00029 case mf::ELseverityLevel::ELsev_incidental:
00030 # endif
00031 case mf::ELseverityLevel::ELsev_success:
00032 case mf::ELseverityLevel::ELsev_zeroSeverity:
00033 case mf::ELseverityLevel::ELsev_unspecified:
00034 sev_ = SDEBUG;
00035 text_ += QString("#505050>");
00036 color_.setRgb(80, 80, 80);
00037 break;
00038
00039 case mf::ELseverityLevel::ELsev_info:
00040 sev_ = SINFO;
00041 text_ += QString("#008000>");
00042 color_.setRgb(0, 128, 0);
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 text_ += QString("#E08000>");
00051 color_.setRgb(224, 128, 0);
00052 break;
00053
00054 case mf::ELseverityLevel::ELsev_error:
00055 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00056 case mf::ELseverityLevel::ELsev_error2:
00057 case mf::ELseverityLevel::ELsev_next:
00058 case mf::ELseverityLevel::ELsev_severe2:
00059 case mf::ELseverityLevel::ELsev_abort:
00060 case mf::ELseverityLevel::ELsev_fatal:
00061 # endif
00062 case mf::ELseverityLevel::ELsev_severe:
00063 case mf::ELseverityLevel::ELsev_highestSeverity:
00064 sev_ = SERROR;
00065 text_ += QString("#FF0000>");
00066 color_.setRgb(255, 0, 0);
00067 break;
00068
00069 default: break;
00070 }
00071
00072 shortText_ = QString(text_);
00073 shortText_ += QString("<pre style=\"margin-top: 0; margin-bottom: 0;\">");
00074 shortText_ += QString(msg.message().c_str()).trimmed().toHtmlEscaped();
00075 shortText_ += QString("</pre></font>");
00076
00077
00078 text_ += QString("<pre>")
00079 + QString(severity.getName().c_str()).toHtmlEscaped() + " / "
00080 + QString(msg.category().c_str()).toHtmlEscaped() + "<br>"
00081 + QString(msg.timestr().c_str()).toHtmlEscaped() + "<br>"
00082 + QString(msg.hostname().c_str()).toHtmlEscaped() + " ("
00083 + QString(msg.hostaddr().c_str()).toHtmlEscaped() + ")<br>"
00084 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00085 + QString(msg.process().c_str()).toHtmlEscaped()
00086 #endif
00087 + " ("
00088 + QString::number(msg.pid()) + ")";
00089
00090 if (msg.file().compare("--"))
00091 text_ += QString(" / ") + QString(msg.file().c_str()).toHtmlEscaped()
00092 + QString(":") + QString::number(msg.line());
00093
00094 text_ += QString("<br>")
00095 + QString(msg.application().c_str()).toHtmlEscaped() + " / "
00096 + QString(msg.module().c_str()).toHtmlEscaped() + " / "
00097 + QString(msg.context().c_str()).toHtmlEscaped() + "<br>"
00098 + QString(msg.message().c_str()).toHtmlEscaped()
00099 + QString("</pre>");
00100
00101 text_ += QString("</font>");
00102 }