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
00050 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
00051 ELTRACE(const fhicl::ParameterSet& pset);
00052 #else
00053 ELTRACE(Parameters const& pset);
00054 #endif
00055
00056 virtual void fillPrefix(std::ostringstream&, const ErrorObj&) override;
00057
00058 virtual void fillUsrMsg(std::ostringstream&, const ErrorObj&) override;
00059
00060 virtual void fillSuffix(std::ostringstream&, const ErrorObj&) override {}
00061
00062 virtual void routePayload(const std::ostringstream&, const ErrorObj&) override;
00063
00064 };
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 #if MESSAGEFACILITY_HEX_VERSION < 0x20103
00075 ELTRACE::ELTRACE(const fhicl::ParameterSet& pset)
00076 : ELdestination(pset)
00077 {
00078 size_t msk;
00079
00080 if (pset.get_if_present<size_t>("lvls", msk))
00081 TRACE_CNTL("lvlmskS", msk);
00082
00083 if (pset.get_if_present<size_t>("lvlm", msk))
00084 TRACE_CNTL("lvlmskM", msk);
00085
00086 TLOG(TLVL_INFO) << "ELTRACE MessageLogger destination plugin initialized.";
00087 }
00088 #else
00089 ELTRACE::ELTRACE(Parameters const& pset)
00090 : ELdestination(pset().elDestConfig())
00091 {
00092 size_t msk;
00093
00094 if (pset().lvls() != 0)
00095 {
00096 msk = pset().lvls();
00097 TRACE_CNTL("lvlmskS", msk);
00098 }
00099 if (pset().lvlm() != 0)
00100 {
00101 msk = pset().lvlm();
00102 TRACE_CNTL("lvlmskM", msk);
00103 }
00104
00105 TLOG(TLVL_INFO) << "ELTRACE MessageLogger destination plugin initialized.";
00106 }
00107
00108 #endif
00109
00110
00111
00112
00113 void ELTRACE::fillPrefix(std::ostringstream& oss, const ErrorObj& msg)
00114 {
00115 const auto& xid = msg.xid();
00116
00117 oss << xid.application() << ", ";
00118 oss << xid.id() << ": ";
00119
00120
00121 }
00122
00123
00124
00125
00126 void ELTRACE::fillUsrMsg(std::ostringstream& oss, const ErrorObj& msg)
00127 {
00128 std::ostringstream tmposs;
00129 ELdestination::fillUsrMsg(tmposs, msg);
00130
00131
00132 const std::string& usrMsg = !tmposs.str().compare(0, 1, "\n") ? tmposs.str().erase(0, 1) : tmposs.str();
00133
00134 oss << usrMsg;
00135 }
00136
00137
00138
00139
00140 void ELTRACE::routePayload(const std::ostringstream& oss, const ErrorObj& msg)
00141 {
00142 const auto& xid = msg.xid();
00143 auto message = oss.str();
00144
00145 auto level = xid.severity().getLevel();
00146 auto lvlNum = 0;
00147
00148 switch (level)
00149 {
00150 case mf::ELseverityLevel::ELsev_success:
00151 case mf::ELseverityLevel::ELsev_zeroSeverity:
00152 case mf::ELseverityLevel::ELsev_unspecified:
00153 lvlNum = 3;
00154 break;
00155
00156 case mf::ELseverityLevel::ELsev_info:
00157 lvlNum = 2;
00158 break;
00159
00160 case mf::ELseverityLevel::ELsev_warning:
00161 lvlNum = 1;
00162 break;
00163 }
00164 TRACE(lvlNum, message);
00165 }
00166 }
00167
00168
00169
00170
00171
00172
00173
00174 #ifndef EXTERN_C_FUNC_DECLARE_START
00175 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
00176 #endif
00177
00178 EXTERN_C_FUNC_DECLARE_START
00179 auto makePlugin(const std::string&,
00180 const fhicl::ParameterSet& pset)
00181 {
00182 return std::make_unique<mfplugins::ELTRACE>(pset);
00183 }
00184 }
00185
00186 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)