1 #include "cetlib/PluginTypeDeducer.h"
2 #include "fhiclcpp/ParameterSet.h"
3 #if MESSAGEFACILITY_HEX_VERSION >= 0x20106 // v2_01_06 => cetlib v3_02_00 => new clang support
4 #include "cetlib/ProvideMakePluginMacros.h"
7 #include "messagefacility/MessageService/ELdestination.h"
8 #include "messagefacility/Utilities/ELseverityLevel.h"
9 #if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
10 # include "messagefacility/MessageService/ELcontextSupplier.h"
11 # include "messagefacility/MessageLogger/MessageDrop.h"
13 #include "messagefacility/Utilities/exception.h"
14 #include "cetlib/compiler_macros.h"
16 #define TRACE_NAME "MessageFacility"
18 #if GCC_VERSION >= 701000 || defined(__clang__)
19 #pragma GCC diagnostic push
20 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
25 #if GCC_VERSION >= 701000 || defined(__clang__)
26 #pragma GCC diagnostic pop
32 using mf::service::ELdestination;
33 using mf::ELseverityLevel;
34 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
35 using mf::service::ELcontextSupplier;
45 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
48 fhicl::TableFragment<ELdestination::Config> elDestConfig;
49 fhicl::Atom<size_t> lvls{ fhicl::Name{
"lvls" },fhicl::Comment{
"TRACE level mask for Slow output" },0 };
50 fhicl::Atom<size_t> lvlm{ fhicl::Name{
"lvlm" },fhicl::Comment{
"TRACE level mask for Memory output" },0 };
52 using Parameters = fhicl::WrappedTable<Config>;
57 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
58 ELTRACE(
const fhicl::ParameterSet& pset);
60 ELTRACE(Parameters
const& pset);
63 virtual void fillPrefix(std::ostringstream&,
const ErrorObj&
64 #
if MESSAGEFACILITY_HEX_VERSION < 0x20002
65 ,
const ELcontextSupplier&
69 virtual void fillUsrMsg(std::ostringstream&,
const ErrorObj&)
override;
71 virtual void fillSuffix(std::ostringstream&,
const ErrorObj&)
override {}
73 virtual void routePayload(
const std::ostringstream&,
const ErrorObj&
74 #
if MESSAGEFACILITY_HEX_VERSION < 0x20002
75 ,
const ELcontextSupplier&
89 #if MESSAGEFACILITY_HEX_VERSION < 0x20103
90 ELTRACE::ELTRACE(
const fhicl::ParameterSet& pset)
95 if (pset.get_if_present<
size_t>(
"lvls",msk))
96 TRACE_CNTL(
"lvlmskS",msk);
98 if (pset.get_if_present<
size_t>(
"lvlm",msk))
99 TRACE_CNTL(
"lvlmskM",msk);
101 TLOG(TLVL_INFO) <<
"ELTRACE MessageLogger destination plugin initialized.";
104 ELTRACE::ELTRACE(Parameters
const& pset)
105 : ELdestination(pset().elDestConfig())
109 if (pset().lvls() != 0) {
111 TRACE_CNTL(
"lvlmskS", msk);
113 if (pset().lvlm() != 0)
116 TRACE_CNTL(
"lvlmskM", msk);
119 TLOG(TLVL_INFO) <<
"ELTRACE MessageLogger destination plugin initialized.";
127 void ELTRACE::fillPrefix(std::ostringstream& oss,
const ErrorObj& msg
128 #
if MESSAGEFACILITY_HEX_VERSION < 0x20002
129 , ELcontextSupplier
const&
133 const auto& xid = msg.xid();
135 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
136 oss << xid.application() <<
", ";
137 oss << xid.id() <<
": ";
139 oss << xid.application <<
", ";
140 oss << xid.id <<
": ";
149 void ELTRACE::fillUsrMsg(std::ostringstream& oss,
const ErrorObj& msg)
151 std::ostringstream tmposs;
152 ELdestination::fillUsrMsg(tmposs, msg);
155 const std::string& usrMsg = !tmposs.str().compare(0, 1,
"\n") ? tmposs.str().erase(0, 1) : tmposs.str();
163 void ELTRACE::routePayload(
const std::ostringstream& oss,
const ErrorObj& msg
164 #
if MESSAGEFACILITY_HEX_VERSION < 0x20002
165 , ELcontextSupplier
const&
169 const auto& xid = msg.xid();
170 auto message = oss.str();
172 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
173 auto level = xid.severity().getLevel();
175 auto level = xid.severity.getLevel();
181 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
182 case mf::ELseverityLevel::ELsev_incidental:
184 case mf::ELseverityLevel::ELsev_success:
185 case mf::ELseverityLevel::ELsev_zeroSeverity:
186 case mf::ELseverityLevel::ELsev_unspecified:
190 case mf::ELseverityLevel::ELsev_info:
194 case mf::ELseverityLevel::ELsev_warning:
195 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
196 case mf::ELseverityLevel::ELsev_warning2:
201 TRACE(lvlNum, message);
211 #ifndef EXTERN_C_FUNC_DECLARE_START
212 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
215 EXTERN_C_FUNC_DECLARE_START
216 auto makePlugin(
const std::string&,
217 const fhicl::ParameterSet& pset)
219 return std::make_unique<mfplugins::ELTRACE>(pset);
223 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)
Message Facility destination which logs messages to a TRACE buffer