1 #include "cetlib/PluginTypeDeducer.h"
2 #include "fhiclcpp/ParameterSet.h"
4 #include "messagefacility/MessageService/ELdestination.h"
5 #include "messagefacility/Utilities/ELseverityLevel.h"
6 #if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
7 # include "messagefacility/MessageService/ELcontextSupplier.h"
8 # include "messagefacility/MessageLogger/MessageDrop.h"
10 #include "messagefacility/Utilities/exception.h"
12 #define TRACE_NAME "MessageFacility"
18 using mf::service::ELdestination;
19 using mf::ELseverityLevel;
20 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
21 using mf::service::ELcontextSupplier;
32 ELTRACE(
const fhicl::ParameterSet& pset);
34 virtual void fillPrefix(std::ostringstream&,
const ErrorObj&
35 #
if MESSAGEFACILITY_HEX_VERSION < 0x20002
36 ,
const ELcontextSupplier&
40 virtual void fillUsrMsg(std::ostringstream&,
const ErrorObj&)
override;
42 virtual void fillSuffix(std::ostringstream&,
const ErrorObj&)
override {}
44 virtual void routePayload(
const std::ostringstream&,
const ErrorObj&
45 #
if MESSAGEFACILITY_HEX_VERSION < 0x20002
46 ,
const ELcontextSupplier&
51 int consecutive_success_count_;
53 int next_error_report_;
54 int error_report_backoff_factor_;
66 ELTRACE::ELTRACE(
const fhicl::ParameterSet& pset)
68 , consecutive_success_count_(0)
70 , next_error_report_(1)
71 , error_report_backoff_factor_()
75 if (pset.get_if_present<
size_t>(
"lvls",msk))
76 TRACE_CNTL(
"lvlmskS",msk);
78 if (pset.get_if_present<
size_t>(
"lvlm",msk))
79 TRACE_CNTL(
"lvlmskM",msk);
81 error_report_backoff_factor_ = pset.get<
int>(
"error_report_backoff_factor", 10);
82 TRACE(3,
"ELTRACE MessageLogger destination plugin initialized.");
88 void ELTRACE::fillPrefix(std::ostringstream& oss,
const ErrorObj& msg
89 #
if MESSAGEFACILITY_HEX_VERSION < 0x20002
90 , ELcontextSupplier
const&
94 const auto& xid = msg.xid();
96 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
97 oss << xid.application() <<
", ";
98 oss << xid.id() <<
": ";
100 oss << xid.application <<
", ";
101 oss << xid.id <<
": ";
110 void ELTRACE::fillUsrMsg(std::ostringstream& oss,
const ErrorObj& msg)
112 std::ostringstream tmposs;
113 ELdestination::fillUsrMsg(tmposs, msg);
116 const std::string& usrMsg = !tmposs.str().compare(0, 1,
"\n") ? tmposs.str().erase(0, 1) : tmposs.str();
124 void ELTRACE::routePayload(
const std::ostringstream& oss,
const ErrorObj& msg
125 #
if MESSAGEFACILITY_HEX_VERSION < 0x20002
126 , ELcontextSupplier
const&
130 const auto& xid = msg.xid();
131 auto message = oss.str();
133 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
134 auto level = xid.severity().getLevel();
136 auto level = xid.severity.getLevel();
142 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
143 case mf::ELseverityLevel::ELsev_incidental:
145 case mf::ELseverityLevel::ELsev_success:
146 case mf::ELseverityLevel::ELsev_zeroSeverity:
147 case mf::ELseverityLevel::ELsev_unspecified:
151 case mf::ELseverityLevel::ELsev_info:
155 case mf::ELseverityLevel::ELsev_warning:
156 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
157 case mf::ELseverityLevel::ELsev_warning2:
162 TRACE(lvlNum, message);
174 auto makePlugin(
const std::string&,
175 const fhicl::ParameterSet& pset)
177 return std::make_unique<mfplugins::ELTRACE>(pset);
181 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)
Message Facility destination which logs messages to a TRACE buffer