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 #include "messagefacility/Utilities/exception.h"
00010 #include "cetlib/compiler_macros.h"
00011
00012 #define TRACE_NAME "MessageFacility"
00013
00014 #if GCC_VERSION >= 701000 || defined(__clang__)
00015 #pragma GCC diagnostic push
00016 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
00017 #endif
00018
00019 #include "trace.h"
00020
00021 #if GCC_VERSION >= 701000 || defined(__clang__)
00022 #pragma GCC diagnostic pop
00023 #endif
00024
00025
00026 namespace mfplugins
00027 {
00028 using mf::service::ELdestination;
00029 using mf::ELseverityLevel;
00030 using mf::ErrorObj;
00031
00035 class ELTRACE : public ELdestination
00036 {
00037
00038 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
00039 struct Config
00040 {
00041 fhicl::TableFragment<ELdestination::Config> elDestConfig;
00042 fhicl::Atom<size_t> lvls{ fhicl::Name{ "lvls" },fhicl::Comment{ "TRACE level mask for Slow output" },0 };
00043 fhicl::Atom<size_t> lvlm{ fhicl::Name{ "lvlm" },fhicl::Comment{ "TRACE level mask for Memory output" },0 };
00044 };
00045 using Parameters = fhicl::WrappedTable<Config>;
00046 #endif
00047
00048 public:
00049
00054 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
00055 ELTRACE(const fhicl::ParameterSet& pset);
00056 #else
00057 ELTRACE(Parameters const& pset);
00058 #endif
00059
00065 virtual void fillPrefix(std::ostringstream& o, const ErrorObj& e) override;
00066
00072 virtual void fillUsrMsg(std::ostringstream& o, const ErrorObj& e) override;
00073
00077 virtual void fillSuffix(std::ostringstream&, const ErrorObj&) override {}
00078
00084 virtual void routePayload(const std::ostringstream& o, const ErrorObj& e) override;
00085
00086 };
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 #if MESSAGEFACILITY_HEX_VERSION < 0x20103
00097 ELTRACE::ELTRACE(const fhicl::ParameterSet& pset)
00098 : ELdestination(pset)
00099 {
00100 size_t msk;
00101
00102 if (pset.get_if_present<size_t>("lvls", msk))
00103 TRACE_CNTL("lvlmskS", msk);
00104
00105 if (pset.get_if_present<size_t>("lvlm", msk))
00106 TRACE_CNTL("lvlmskM", msk);
00107
00108 TLOG(TLVL_INFO) << "ELTRACE MessageLogger destination plugin initialized.";
00109 }
00110 #else
00111 ELTRACE::ELTRACE(Parameters const& pset)
00112 : ELdestination(pset().elDestConfig())
00113 {
00114 size_t msk;
00115
00116 if (pset().lvls() != 0)
00117 {
00118 msk = pset().lvls();
00119 TRACE_CNTL("lvlmskS", msk);
00120 }
00121 if (pset().lvlm() != 0)
00122 {
00123 msk = pset().lvlm();
00124 TRACE_CNTL("lvlmskM", msk);
00125 }
00126
00127 TLOG(TLVL_INFO) << "ELTRACE MessageLogger destination plugin initialized.";
00128 }
00129
00130 #endif
00131
00132
00133
00134
00135 void ELTRACE::fillPrefix(std::ostringstream& oss, const ErrorObj& msg)
00136 {
00137 const auto& xid = msg.xid();
00138
00139 oss << xid.application() << ", ";
00140 oss << xid.id() << ": ";
00141
00142
00143 }
00144
00145
00146
00147
00148 void ELTRACE::fillUsrMsg(std::ostringstream& oss, const ErrorObj& msg)
00149 {
00150 std::ostringstream tmposs;
00151 ELdestination::fillUsrMsg(tmposs, msg);
00152
00153
00154 const std::string& usrMsg = !tmposs.str().compare(0, 1, "\n") ? tmposs.str().erase(0, 1) : tmposs.str();
00155
00156 oss << usrMsg;
00157 }
00158
00159
00160
00161
00162 void ELTRACE::routePayload(const std::ostringstream& oss, const ErrorObj& msg)
00163 {
00164 const auto& xid = msg.xid();
00165 auto message = oss.str();
00166
00167 auto level = xid.severity().getLevel();
00168 auto lvlNum = 0;
00169
00170 switch (level)
00171 {
00172 case mf::ELseverityLevel::ELsev_success:
00173 case mf::ELseverityLevel::ELsev_zeroSeverity:
00174 case mf::ELseverityLevel::ELsev_unspecified:
00175 lvlNum = 3;
00176 break;
00177
00178 case mf::ELseverityLevel::ELsev_info:
00179 lvlNum = 2;
00180 break;
00181
00182 case mf::ELseverityLevel::ELsev_warning:
00183 lvlNum = 1;
00184 break;
00185 }
00186 TRACE(lvlNum, message);
00187 }
00188 }
00189
00190
00191
00192
00193
00194
00195
00196 #ifndef EXTERN_C_FUNC_DECLARE_START
00197 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
00198 #endif
00199
00200 EXTERN_C_FUNC_DECLARE_START
00201 auto makePlugin(const std::string&,
00202 const fhicl::ParameterSet& pset)
00203 {
00204 return std::make_unique<mfplugins::ELTRACE>(pset);
00205 }
00206 }
00207
00208 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)