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 #include "messagefacility/Utilities/exception.h"
9 #include "cetlib/compiler_macros.h"
16 #if MESSAGEFACILITY_HEX_VERSION < 0x20201 // format changed to format_ for s67
17 #define format_ format
22 using namespace mf::service;
23 using mf::ELseverityLevel;
31 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
34 fhicl::TableFragment<ELostreamOutput::Config> elOstrConfig;
35 fhicl::Atom<std::string> delimiter{ fhicl::Name{
"field_delimiter" },fhicl::Comment{
"String to print between each message field" },
" " };
37 using Parameters = fhicl::WrappedTable<Config>;
44 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
55 virtual void fillPrefix(std::ostringstream& o,
const ErrorObj& e)
override;
61 virtual void fillUsrMsg(std::ostringstream& o,
const ErrorObj& e)
override;
67 virtual void fillSuffix(std::ostringstream& o,
const ErrorObj& e)
override;
70 std::string delimeter_;
82 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
84 : ELostreamOutput(pset, cet::ostream_handle{ std::cout },
false)
85 , delimeter_(pset.get<std::string>(
"field_delimeter",
" "))
88 : ELostreamOutput(pset().elOstrConfig(), cet::ostream_handle{ std::cout },
false)
89 , delimeter_(pset().delimiter())
102 #if MESSAGEFACILITY_HEX_VERSION < 0x20201 // format changed to format_ for s67
103 format_.preambleMode =
true;
106 auto const& xid = msg.xid();
109 auto app = xid.application();
110 auto module = xid.module();
111 auto subroutine = xid.subroutine();
112 std::replace(
id.begin(),
id.end(),
' ',
'-');
113 std::replace(app.begin(), app.end(),
' ',
'-');
114 std::replace(module.begin(), module.end(),
' ',
'-');
115 std::replace(subroutine.begin(), subroutine.end(),
' ',
'-');
117 emitToken(oss,
"%MSG");
118 emitToken(oss, xid.severity().getSymbol());
119 emitToken(oss, delimeter_);
121 emitToken(oss, msg.idOverflow());
123 emitToken(oss, delimeter_);
127 if (format_.want(SERIAL))
129 std::ostringstream s;
131 emitToken(oss,
"[serial #" + s.str() +
"]");
132 emitToken(oss, delimeter_);
137 bool needAspace =
true;
138 if (format_.want(EPILOGUE_SEPARATE))
140 if (module.length() + subroutine.length() > 0)
142 emitToken(oss,
"\n");
145 else if (format_.want(TIMESTAMP) && !format_.want(TIME_SEPARATE))
147 emitToken(oss,
"\n");
151 if (format_.want(MODULE) && (module.length() > 0))
155 emitToken(oss, delimeter_);
158 emitToken(oss, module +
" ");
160 if (format_.want(SUBROUTINE) && (subroutine.length() > 0))
164 emitToken(oss, delimeter_);
167 emitToken(oss, subroutine +
"()");
168 emitToken(oss, delimeter_);
173 if (format_.want(TIMESTAMP))
175 if (format_.want(TIME_SEPARATE))
177 emitToken(oss,
"\n");
182 emitToken(oss, delimeter_);
185 emitToken(oss, format_.timestamp(msg.timestamp()));
186 emitToken(oss, delimeter_);
191 if (format_.want(SOME_CONTEXT))
195 emitToken(oss, delimeter_);
198 emitToken(oss, msg.context());
207 if (!format_.want(TEXT))
return;
209 #if MESSAGEFACILITY_HEX_VERSION < 0x20201 // format changed to format_ for s67
210 format_.preambleMode =
false;
212 auto const usrMsgStart = std::next(msg.items().cbegin(), 4);
213 auto it = msg.items().cbegin();
216 if (
true || !msg.is_verbatim())
220 while (it != usrMsgStart)
222 if (!it->compare(
" ") && !std::next(it)->compare(
"--"))
230 emitToken(oss, *it++);
235 if (format_.want(NO_LINE_BREAKS)) emitToken(oss,
" ==> ");
236 else emitToken(oss,
"",
true);
240 auto const end = msg.items().cend();
241 for (; it != end; ++it)
252 if ((
true || !msg.is_verbatim()) && !format_.want(NO_LINE_BREAKS))
254 emitToken(oss,
"\n%MSG");
269 #ifndef EXTERN_C_FUNC_DECLARE_START
270 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
273 EXTERN_C_FUNC_DECLARE_START
274 auto makePlugin(
const std::string&,
275 const fhicl::ParameterSet& pset)
277 return std::make_unique<mfplugins::ELFriendly>(pset);
281 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)
Parser-Friendly Message Facility destination plugin
virtual void fillSuffix(std::ostringstream &o, const ErrorObj &e) override
Fill the "Suffix" portion of the message.
ELFriendly(const fhicl::ParameterSet &pset)
ELFriendly Constructor
virtual void fillUsrMsg(std::ostringstream &o, const ErrorObj &e) override
Fill the "User Message" portion of the message.
virtual void fillPrefix(std::ostringstream &o, const ErrorObj &e) override
Fill the "Prefix" portion of the message.