1 #include "cetlib/PluginTypeDeducer.h"
2 #include "cetlib/ostream_handle.h"
3 #include "fhiclcpp/ParameterSet.h"
5 #include "cetlib/compiler_macros.h"
6 #include "messagefacility/MessageService/ELdestination.h"
7 #include "messagefacility/MessageService/ELostreamOutput.h"
8 #include "messagefacility/Utilities/ELseverityLevel.h"
9 #include "messagefacility/Utilities/exception.h"
17 using namespace mf::service;
34 fhicl::Atom<std::string> delimiter = fhicl::Atom<std::string>{
35 fhicl::Name{
"field_delimiter"}, fhicl::Comment{
"String to print between each message field"},
" "};
52 void fillPrefix(std::ostringstream& o,
const ErrorObj& msg)
override;
58 void fillUsrMsg(std::ostringstream& o,
const ErrorObj& msg)
override;
64 void fillSuffix(std::ostringstream& o,
const ErrorObj& msg)
override;
67 std::string delimeter_;
79 : ELostreamOutput(pset().elOstrConfig(), cet::ostream_handle{std::cout},
false), delimeter_(pset().delimiter()) {}
91 auto const& xid = msg.xid();
94 auto app = xid.application();
95 auto module = xid.module();
96 auto subroutine = xid.subroutine();
97 std::replace(
id.begin(),
id.end(),
' ',
'-');
98 std::replace(app.begin(), app.end(),
' ',
'-');
99 std::replace(module.begin(), module.end(),
' ',
'-');
100 std::replace(subroutine.begin(), subroutine.end(),
' ',
'-');
102 emitToken(oss,
"%MSG");
103 emitToken(oss, xid.severity().getSymbol());
104 emitToken(oss, delimeter_);
106 emitToken(oss, msg.idOverflow());
108 emitToken(oss, delimeter_);
112 if (format_.want(SERIAL))
114 std::ostringstream s;
116 emitToken(oss,
"[serial #" + s.str() +
"]");
117 emitToken(oss, delimeter_);
122 bool needAspace =
true;
123 if (format_.want(EPILOGUE_SEPARATE))
125 if (module.length() + subroutine.length() > 0)
127 emitToken(oss,
"\n");
130 else if (format_.want(TIMESTAMP) && !format_.want(TIME_SEPARATE))
132 emitToken(oss,
"\n");
136 if (format_.want(MODULE) && (module.length() > 0))
140 emitToken(oss, delimeter_);
143 emitToken(oss, module +
" ");
145 if (format_.want(SUBROUTINE) && (subroutine.length() > 0))
149 emitToken(oss, delimeter_);
152 emitToken(oss, subroutine +
"()");
153 emitToken(oss, delimeter_);
158 if (format_.want(TIMESTAMP))
160 if (format_.want(TIME_SEPARATE))
162 emitToken(oss,
"\n");
167 emitToken(oss, delimeter_);
170 emitToken(oss, format_.timestamp(msg.timestamp()));
171 emitToken(oss, delimeter_);
176 if (format_.want(SOME_CONTEXT))
180 emitToken(oss, delimeter_);
183 emitToken(oss, msg.context());
190 if (!format_.want(TEXT))
195 auto const usrMsgStart = std::next(msg.items().cbegin(), 4);
196 auto it = msg.items().cbegin();
201 while (it != usrMsgStart)
203 if ((*it ==
" ") && (*std::next(it) ==
"--"))
211 emitToken(oss, *it++);
216 if (format_.want(NO_LINE_BREAKS))
218 emitToken(oss,
" ==> ");
222 emitToken(oss,
"",
true);
226 auto const end = msg.items().cend();
227 for (; it != end; ++it)
236 if (!format_.want(NO_LINE_BREAKS))
238 emitToken(oss,
"\n%MSG");
251 #ifndef EXTERN_C_FUNC_DECLARE_START
252 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
255 EXTERN_C_FUNC_DECLARE_START
256 auto makePlugin(
const std::string& ,
const fhicl::ParameterSet& pset)
258 return std::make_unique<mfplugins::ELFriendly>(pset);
262 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.