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