1 #include "cetlib/PluginTypeDeducer.h"
2 #include "cetlib/ostream_handle.h"
3 #include "fhiclcpp/ParameterSet.h"
5 #include "messagefacility/MessageService/ELdestination.h"
6 #include "messagefacility/MessageService/ELostreamOutput.h"
7 #include "messagefacility/Utilities/ELseverityLevel.h"
8 #if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
9 # include "messagefacility/MessageService/ELcontextSupplier.h"
10 # include "messagefacility/MessageLogger/MessageDrop.h"
12 #include "messagefacility/Utilities/exception.h"
22 using namespace mf::service;
23 using mf::ELseverityLevel;
35 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
36 virtual void fillPrefix(std::ostringstream&,
const ErrorObj&)
override;
38 virtual void fillPrefix(std::ostringstream&,
const ErrorObj&,
const ELcontextSupplier&)
override;
40 virtual void fillUsrMsg(std::ostringstream&,
const ErrorObj&)
override;
41 virtual void fillSuffix(std::ostringstream&,
const ErrorObj&)
override;
44 std::string delimeter_;
56 ELFriendly::ELFriendly(
const fhicl::ParameterSet& pset)
57 : ELostreamOutput(pset, cet::ostream_handle{ std::cout },
false)
58 , delimeter_(pset.get<std::string>(
"field_delimeter",
" "))
65 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
66 void ELFriendly::fillPrefix(std::ostringstream& oss,
const ErrorObj& msg)
68 void ELFriendly::fillPrefix(std::ostringstream& oss,
const ErrorObj& msg, ELcontextSupplier
const& contextSupplier)
75 format.preambleMode =
true;
77 auto const& xid = msg.xid();
79 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
81 auto app = xid.application();
82 auto module = xid.module();
83 auto subroutine = xid.subroutine();
86 auto app = xid.application;
87 auto process = xid.process;
88 auto module = xid.module;
89 auto subroutine = xid.subroutine;
90 std::replace(process.begin(), process.end(),
' ',
'-');
91 # define emitToken emit
93 std::replace(
id.begin(),
id.end(),
' ',
'-');
94 std::replace(app.begin(), app.end(),
' ',
'-');
95 std::replace(module.begin(), module.end(),
' ',
'-');
96 std::replace(subroutine.begin(), subroutine.end(),
' ',
'-');
98 emitToken(oss,
"%MSG");
99 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
100 emitToken(oss, xid.severity().getSymbol());
102 emit(oss, xid.severity.getSymbol());
104 emitToken(oss, delimeter_);
106 emitToken(oss, msg.idOverflow());
108 emitToken(oss, delimeter_);
112 if (format.want(SERIAL)) {
113 std::ostringstream s;
115 emitToken(oss,
"[serial #" + s.str() +
"]");
116 emitToken(oss, delimeter_);
121 bool needAspace =
true;
122 if (format.want(EPILOGUE_SEPARATE)) {
123 if (module.length() + subroutine.length() > 0) {
124 emitToken(oss,
"\n");
127 else if (format.want(TIMESTAMP) && !format.want(TIME_SEPARATE)) {
128 emitToken(oss,
"\n");
132 if (format.want(MODULE) && (module.length() > 0)) {
134 emitToken(oss, delimeter_);
137 emitToken(oss, module +
" ");
139 if (format.want(SUBROUTINE) && (subroutine.length() > 0)) {
141 emitToken(oss, delimeter_);
144 emitToken(oss, subroutine +
"()");
145 emitToken(oss, delimeter_);
150 if (format.want(TIMESTAMP)) {
151 if (format.want(TIME_SEPARATE)) {
152 emitToken(oss,
"\n");
156 emitToken(oss, delimeter_);
159 emitToken(oss, format.timestamp(msg.timestamp()));
160 emitToken(oss, delimeter_);
165 if (format.want(SOME_CONTEXT)) {
167 emitToken(oss, delimeter_);
170 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
171 emitToken(oss, msg.context());
173 if (format.want(FULL_CONTEXT)) {
174 emit(oss, contextSupplier.fullContext());
177 emit(oss, contextSupplier.context());
186 void ELFriendly::fillUsrMsg(std::ostringstream& oss, ErrorObj
const& msg)
188 if (!format.want(TEXT))
return;
190 format.preambleMode =
false;
191 auto const usrMsgStart = std::next(msg.items().cbegin(), 4);
192 auto it = msg.items().cbegin();
195 if (
true || !msg.is_verbatim()) {
198 while (it != usrMsgStart) {
199 if (!it->compare(
" ") && !std::next(it)->compare(
"--")) {
205 emitToken(oss, *it++);
210 if (format.want(NO_LINE_BREAKS)) emitToken(oss,
" ==> ");
211 else emitToken(oss,
"",
true);
215 auto const end = msg.items().cend();
216 for (; it != end; ++it) {
224 void ELFriendly::fillSuffix(std::ostringstream& oss, ErrorObj
const& msg)
226 if ((
true || !msg.is_verbatim()) && !format.want(NO_LINE_BREAKS)) {
227 emitToken(oss,
"\n%MSG");
244 auto makePlugin(
const std::string&,
245 const fhicl::ParameterSet& pset)
247 return std::make_unique<mfplugins::ELFriendly>(pset);
251 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)
Parser-Friendly Message Facility destination plugin