00001 #include "cetlib/PluginTypeDeducer.h"
00002 #include "fhiclcpp/ParameterSet.h"
00003 #if MESSAGEFACILITY_HEX_VERSION >= 0x20106 // v2_01_06 => cetlib v3_02_00 => new clang support
00004 #include "cetlib/ProvideMakePluginMacros.h"
00005 #endif
00006
00007 #include "messagefacility/MessageService/ELdestination.h"
00008 #include "messagefacility/Utilities/ELseverityLevel.h"
00009 #if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00010 # include "messagefacility/MessageService/ELcontextSupplier.h"
00011 # include "messagefacility/MessageLogger/MessageDrop.h"
00012 #endif
00013 #include "messagefacility/Utilities/exception.h"
00014 #include "cetlib/compiler_macros.h"
00015
00016 #define TRACE_NAME "MessageFacility"
00017
00018 #if GCC_VERSION >= 701000 || defined(__clang__)
00019 #pragma GCC diagnostic push
00020 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
00021 #endif
00022
00023 #include "trace.h"
00024
00025 #if GCC_VERSION >= 701000 || defined(__clang__)
00026 #pragma GCC diagnostic pop
00027 #endif
00028
00029
00030 namespace mfplugins
00031 {
00032 using mf::service::ELdestination;
00033 using mf::ELseverityLevel;
00034 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00035 using mf::service::ELcontextSupplier;
00036 # endif
00037 using mf::ErrorObj;
00038
00042 class ELTRACE : public ELdestination
00043 {
00044
00045 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
00046 struct Config
00047 {
00048 fhicl::TableFragment<ELdestination::Config> elDestConfig;
00049 fhicl::Atom<size_t> lvls{ fhicl::Name{ "lvls" },fhicl::Comment{ "TRACE level mask for Slow output" },0 };
00050 fhicl::Atom<size_t> lvlm{ fhicl::Name{ "lvlm" },fhicl::Comment{ "TRACE level mask for Memory output" },0 };
00051 };
00052 using Parameters = fhicl::WrappedTable<Config>;
00053 #endif
00054
00055 public:
00056
00057 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
00058 ELTRACE(const fhicl::ParameterSet& pset);
00059 #else
00060 ELTRACE(Parameters const& pset);
00061 #endif
00062
00063 virtual void fillPrefix(std::ostringstream&, const ErrorObj&
00064 # if MESSAGEFACILITY_HEX_VERSION < 0x20002
00065 , const ELcontextSupplier&
00066 # endif
00067 ) override;
00068
00069 virtual void fillUsrMsg(std::ostringstream&, const ErrorObj&) override;
00070
00071 virtual void fillSuffix(std::ostringstream&, const ErrorObj&) override {}
00072
00073 virtual void routePayload(const std::ostringstream&, const ErrorObj&
00074 # if MESSAGEFACILITY_HEX_VERSION < 0x20002
00075 , const ELcontextSupplier&
00076 # endif
00077 ) override;
00078
00079 };
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 #if MESSAGEFACILITY_HEX_VERSION < 0x20103
00090 ELTRACE::ELTRACE(const fhicl::ParameterSet& pset)
00091 : ELdestination(pset)
00092 {
00093 size_t msk;
00094
00095 if (pset.get_if_present<size_t>("lvls",msk))
00096 TRACE_CNTL("lvlmskS",msk);
00097
00098 if (pset.get_if_present<size_t>("lvlm",msk))
00099 TRACE_CNTL("lvlmskM",msk);
00100
00101 TLOG(TLVL_INFO) << "ELTRACE MessageLogger destination plugin initialized.";
00102 }
00103 #else
00104 ELTRACE::ELTRACE(Parameters const& pset)
00105 : ELdestination(pset().elDestConfig())
00106 {
00107 size_t msk;
00108
00109 if (pset().lvls() != 0) {
00110 msk = pset().lvls();
00111 TRACE_CNTL("lvlmskS", msk);
00112 }
00113 if (pset().lvlm() != 0)
00114 {
00115 msk = pset().lvlm();
00116 TRACE_CNTL("lvlmskM", msk);
00117 }
00118
00119 TLOG(TLVL_INFO) << "ELTRACE MessageLogger destination plugin initialized.";
00120 }
00121
00122 #endif
00123
00124
00125
00126
00127 void ELTRACE::fillPrefix(std::ostringstream& oss, const ErrorObj& msg
00128 # if MESSAGEFACILITY_HEX_VERSION < 0x20002
00129 , ELcontextSupplier const&
00130 # endif
00131 )
00132 {
00133 const auto& xid = msg.xid();
00134
00135 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
00136 oss << xid.application() << ", ";
00137 oss << xid.id() << ": ";
00138 # else
00139 oss << xid.application << ", ";
00140 oss << xid.id << ": ";
00141 # endif
00142
00143
00144 }
00145
00146
00147
00148
00149 void ELTRACE::fillUsrMsg(std::ostringstream& oss, const ErrorObj& msg)
00150 {
00151 std::ostringstream tmposs;
00152 ELdestination::fillUsrMsg(tmposs, msg);
00153
00154
00155 const std::string& usrMsg = !tmposs.str().compare(0, 1, "\n") ? tmposs.str().erase(0, 1) : tmposs.str();
00156
00157 oss << usrMsg;
00158 }
00159
00160
00161
00162
00163 void ELTRACE::routePayload(const std::ostringstream& oss, const ErrorObj& msg
00164 # if MESSAGEFACILITY_HEX_VERSION < 0x20002
00165 , ELcontextSupplier const&
00166 # endif
00167 )
00168 {
00169 const auto& xid = msg.xid();
00170 auto message = oss.str();
00171
00172 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
00173 auto level = xid.severity().getLevel();
00174 # else
00175 auto level = xid.severity.getLevel();
00176 # endif
00177 auto lvlNum = 0;
00178
00179 switch (level)
00180 {
00181 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00182 case mf::ELseverityLevel::ELsev_incidental:
00183 # endif
00184 case mf::ELseverityLevel::ELsev_success:
00185 case mf::ELseverityLevel::ELsev_zeroSeverity:
00186 case mf::ELseverityLevel::ELsev_unspecified:
00187 lvlNum = 3;
00188 break;
00189
00190 case mf::ELseverityLevel::ELsev_info:
00191 lvlNum = 2;
00192 break;
00193
00194 case mf::ELseverityLevel::ELsev_warning:
00195 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
00196 case mf::ELseverityLevel::ELsev_warning2:
00197 # endif
00198 lvlNum = 1;
00199 break;
00200 }
00201 TRACE(lvlNum, message);
00202 }
00203 }
00204
00205
00206
00207
00208
00209
00210
00211 #ifndef EXTERN_C_FUNC_DECLARE_START
00212 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
00213 #endif
00214
00215 EXTERN_C_FUNC_DECLARE_START
00216 auto makePlugin(const std::string&,
00217 const fhicl::ParameterSet& pset)
00218 {
00219 return std::make_unique<mfplugins::ELTRACE>(pset);
00220 }
00221 }
00222
00223 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)