00001 #include "cetlib/PluginTypeDeducer.h"
00002 #include "fhiclcpp/ParameterSet.h"
00003
00004 #include "messagefacility/MessageService/ELdestination.h"
00005 #include "messagefacility/Utilities/ELseverityLevel.h"
00006 #if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00007 # include "messagefacility/MessageService/ELcontextSupplier.h"
00008 # include "messagefacility/MessageLogger/MessageDrop.h"
00009 #endif
00010 #include "messagefacility/Utilities/exception.h"
00011
00012 #define TRACE_NAME "MessageFacility"
00013 #include "trace.h"
00014
00015
00016 namespace mfplugins
00017 {
00018 using mf::service::ELdestination;
00019 using mf::ELseverityLevel;
00020 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00021 using mf::service::ELcontextSupplier;
00022 # endif
00023 using mf::ErrorObj;
00024
00028 class ELTRACE : public ELdestination
00029 {
00030 public:
00031
00032 ELTRACE(const fhicl::ParameterSet& pset);
00033
00034 virtual void fillPrefix(std::ostringstream&, const ErrorObj&
00035 # if MESSAGEFACILITY_HEX_VERSION < 0x20002
00036 , const ELcontextSupplier&
00037 # endif
00038 ) override;
00039
00040 virtual void fillUsrMsg(std::ostringstream&, const ErrorObj&) override;
00041
00042 virtual void fillSuffix(std::ostringstream&, const ErrorObj&) override {}
00043
00044 virtual void routePayload(const std::ostringstream&, const ErrorObj&
00045 # if MESSAGEFACILITY_HEX_VERSION < 0x20002
00046 , const ELcontextSupplier&
00047 # endif
00048 ) override;
00049
00050 private:
00051 int consecutive_success_count_;
00052 int error_count_;
00053 int next_error_report_;
00054 int error_report_backoff_factor_;
00055 };
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 ELTRACE::ELTRACE(const fhicl::ParameterSet& pset)
00067 : ELdestination(pset)
00068 , consecutive_success_count_(0)
00069 , error_count_(0)
00070 , next_error_report_(1)
00071 , error_report_backoff_factor_()
00072 {
00073 size_t msk;
00074
00075 if (pset.get_if_present<size_t>("lvls",msk))
00076 TRACE_CNTL("lvlmskS",msk);
00077
00078 if (pset.get_if_present<size_t>("lvlm",msk))
00079 TRACE_CNTL("lvlmskM",msk);
00080
00081 error_report_backoff_factor_ = pset.get<int>("error_report_backoff_factor", 10);
00082 TRACE(3, "ELTRACE MessageLogger destination plugin initialized.");
00083 }
00084
00085
00086
00087
00088 void ELTRACE::fillPrefix(std::ostringstream& oss, const ErrorObj& msg
00089 # if MESSAGEFACILITY_HEX_VERSION < 0x20002
00090 , ELcontextSupplier const&
00091 # endif
00092 )
00093 {
00094 const auto& xid = msg.xid();
00095
00096 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
00097 oss << xid.application() << ", ";
00098 oss << xid.id() << ": ";
00099 # else
00100 oss << xid.application << ", ";
00101 oss << xid.id << ": ";
00102 # endif
00103
00104
00105 }
00106
00107
00108
00109
00110 void ELTRACE::fillUsrMsg(std::ostringstream& oss, const ErrorObj& msg)
00111 {
00112 std::ostringstream tmposs;
00113 ELdestination::fillUsrMsg(tmposs, msg);
00114
00115
00116 const std::string& usrMsg = !tmposs.str().compare(0, 1, "\n") ? tmposs.str().erase(0, 1) : tmposs.str();
00117
00118 oss << usrMsg;
00119 }
00120
00121
00122
00123
00124 void ELTRACE::routePayload(const std::ostringstream& oss, const ErrorObj& msg
00125 # if MESSAGEFACILITY_HEX_VERSION < 0x20002
00126 , ELcontextSupplier const&
00127 # endif
00128 )
00129 {
00130 const auto& xid = msg.xid();
00131 auto message = oss.str();
00132
00133 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
00134 auto level = xid.severity().getLevel();
00135 # else
00136 auto level = xid.severity.getLevel();
00137 # endif
00138 auto lvlNum = 0;
00139
00140 switch (level)
00141 {
00142 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00143 case mf::ELseverityLevel::ELsev_incidental:
00144 # endif
00145 case mf::ELseverityLevel::ELsev_success:
00146 case mf::ELseverityLevel::ELsev_zeroSeverity:
00147 case mf::ELseverityLevel::ELsev_unspecified:
00148 lvlNum = 3;
00149 break;
00150
00151 case mf::ELseverityLevel::ELsev_info:
00152 lvlNum = 2;
00153 break;
00154
00155 case mf::ELseverityLevel::ELsev_warning:
00156 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00157 case mf::ELseverityLevel::ELsev_warning2:
00158 # endif
00159 lvlNum = 1;
00160 break;
00161 }
00162 TRACE(lvlNum, message);
00163 }
00164 }
00165
00166
00167
00168
00169
00170
00171
00172 extern "C"
00173 {
00174 auto makePlugin(const std::string&,
00175 const fhicl::ParameterSet& pset)
00176 {
00177 return std::make_unique<mfplugins::ELTRACE>(pset);
00178 }
00179 }
00180
00181 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)