1 #include "cetlib/PluginTypeDeducer.h"
2 #include "cetlib/ostream_handle.h"
3 #include "fhiclcpp/ParameterSet.h"
4 #include "fhiclcpp/types/ConfigurationTable.h"
6 #include "cetlib/compiler_macros.h"
7 #include "messagefacility/MessageService/ELdestination.h"
8 #include "messagefacility/MessageService/ELostreamOutput.h"
9 #include "messagefacility/Utilities/ELseverityLevel.h"
10 #include "messagefacility/Utilities/exception.h"
18 using namespace mf::service;
35 fhicl::Atom<std::string> delimiter = fhicl::Atom<std::string>{
36 fhicl::Name{
"field_delimiter"}, fhicl::Comment{
"String to print between each message field"},
" "};
53 void fillPrefix(std::ostringstream& o,
const ErrorObj& msg)
override;
59 void fillUsrMsg(std::ostringstream& o,
const ErrorObj& msg)
override;
65 void fillSuffix(std::ostringstream& o,
const ErrorObj& msg)
override;
68 std::string delimeter_;
80 : ELostreamOutput(pset().elOstrConfig(), cet::ostream_handle{std::cout},
false), delimeter_(pset().delimiter()) {}
92 auto const& xid = msg.xid();
95 auto app = xid.application();
96 auto module = xid.module();
97 auto subroutine = xid.subroutine();
98 std::replace(
id.begin(),
id.end(),
' ',
'-');
99 std::replace(app.begin(), app.end(),
' ',
'-');
100 std::replace(module.begin(), module.end(),
' ',
'-');
101 std::replace(subroutine.begin(), subroutine.end(),
' ',
'-');
103 emitToken(oss,
"%MSG");
104 emitToken(oss, xid.severity().getSymbol());
105 emitToken(oss, delimeter_);
107 emitToken(oss, msg.idOverflow());
109 emitToken(oss, delimeter_);
113 if (format_.want(SERIAL))
115 std::ostringstream s;
117 emitToken(oss,
"[serial #" + s.str() +
"]");
118 emitToken(oss, delimeter_);
123 bool needAspace =
true;
124 if (format_.want(EPILOGUE_SEPARATE))
126 if (module.length() + subroutine.length() > 0)
128 emitToken(oss,
"\n");
131 else if (format_.want(TIMESTAMP) && !format_.want(TIME_SEPARATE))
133 emitToken(oss,
"\n");
137 if (format_.want(MODULE) && (module.length() > 0))
141 emitToken(oss, delimeter_);
144 emitToken(oss, module +
" ");
146 if (format_.want(SUBROUTINE) && (subroutine.length() > 0))
150 emitToken(oss, delimeter_);
153 emitToken(oss, subroutine +
"()");
154 emitToken(oss, delimeter_);
159 if (format_.want(TIMESTAMP))
161 if (format_.want(TIME_SEPARATE))
163 emitToken(oss,
"\n");
168 emitToken(oss, delimeter_);
171 emitToken(oss, format_.timestamp(msg.timestamp()));
172 emitToken(oss, delimeter_);
177 if (format_.want(SOME_CONTEXT))
181 emitToken(oss, delimeter_);
184 emitToken(oss, msg.context());
191 if (!format_.want(TEXT))
196 auto const usrMsgStart = std::next(msg.items().cbegin(), 4);
197 auto it = msg.items().cbegin();
202 while (it != usrMsgStart)
204 if ((*it ==
" ") && (*std::next(it) ==
"--"))
212 emitToken(oss, *it++);
217 if (format_.want(NO_LINE_BREAKS))
219 emitToken(oss,
" ==> ");
223 emitToken(oss,
"",
true);
227 auto const end = msg.items().cend();
228 for (; it != end; ++it)
237 if (!format_.want(NO_LINE_BREAKS))
239 emitToken(oss,
"\n%MSG");
252 #ifndef EXTERN_C_FUNC_DECLARE_START
253 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
256 EXTERN_C_FUNC_DECLARE_START
257 auto makePlugin(
const std::string& ,
const fhicl::ParameterSet& pset)
259 return std::make_unique<mfplugins::ELFriendly>(pset);
263 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)
Parser-Friendly Message Facility destination plugin
void fillUsrMsg(std::ostringstream &o, const ErrorObj &msg) override
Fill the "User Message" portion of the message.
ELFriendly(Parameters const &pset)
ELFriendly Constructor
void fillPrefix(std::ostringstream &o, const ErrorObj &msg) override
Fill the "Prefix" portion of the message.
fhicl::WrappedTable< Config > Parameters
Used for ParameterSet validation.
fhicl::TableFragment< ELostreamOutput::Config > elOstrConfig
Configuration parameters for ELostreamOutput.
Configuration Parameters for ELFriendly.
void fillSuffix(std::ostringstream &o, const ErrorObj &msg) override
Fill the "Suffix" portion of the message.