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"
16 #if MESSAGEFACILITY_HEX_VERSION < 0x20201 // format changed to format_ for s67
17 #define format_ format
21 using namespace mf::service;
22 using mf::ELseverityLevel;
30 fhicl::TableFragment<ELostreamOutput::Config> elOstrConfig;
31 fhicl::Atom<std::string> delimiter{fhicl::Name{
"field_delimiter"},
32 fhicl::Comment{
"String to print between each message field"},
" "};
34 using Parameters = fhicl::WrappedTable<Config>;
48 virtual void fillPrefix(std::ostringstream& o,
const ErrorObj& e)
override;
54 virtual void fillUsrMsg(std::ostringstream& o,
const ErrorObj& e)
override;
60 virtual void fillSuffix(std::ostringstream& o,
const ErrorObj& e)
override;
63 std::string delimeter_;
75 : ELostreamOutput(pset().elOstrConfig(), cet::ostream_handle{std::cout},
false), delimeter_(pset().delimiter()) {}
85 #if MESSAGEFACILITY_HEX_VERSION < 0x20201 // format changed to format_ for s67
86 format_.preambleMode =
true;
89 auto const& xid = msg.xid();
92 auto app = xid.application();
93 auto module = xid.module();
94 auto subroutine = xid.subroutine();
95 std::replace(
id.begin(),
id.end(),
' ',
'-');
96 std::replace(app.begin(), app.end(),
' ',
'-');
97 std::replace(module.begin(), module.end(),
' ',
'-');
98 std::replace(subroutine.begin(), subroutine.end(),
' ',
'-');
100 emitToken(oss,
"%MSG");
101 emitToken(oss, xid.severity().getSymbol());
102 emitToken(oss, delimeter_);
104 emitToken(oss, msg.idOverflow());
106 emitToken(oss, delimeter_);
110 if (format_.want(SERIAL)) {
111 std::ostringstream s;
113 emitToken(oss,
"[serial #" + s.str() +
"]");
114 emitToken(oss, delimeter_);
119 bool needAspace =
true;
120 if (format_.want(EPILOGUE_SEPARATE)) {
121 if (module.length() + subroutine.length() > 0) {
122 emitToken(oss,
"\n");
124 }
else if (format_.want(TIMESTAMP) && !format_.want(TIME_SEPARATE)) {
125 emitToken(oss,
"\n");
129 if (format_.want(MODULE) && (module.length() > 0)) {
131 emitToken(oss, delimeter_);
134 emitToken(oss, module +
" ");
136 if (format_.want(SUBROUTINE) && (subroutine.length() > 0)) {
138 emitToken(oss, delimeter_);
141 emitToken(oss, subroutine +
"()");
142 emitToken(oss, delimeter_);
147 if (format_.want(TIMESTAMP)) {
148 if (format_.want(TIME_SEPARATE)) {
149 emitToken(oss,
"\n");
153 emitToken(oss, delimeter_);
156 emitToken(oss, format_.timestamp(msg.timestamp()));
157 emitToken(oss, delimeter_);
162 if (format_.want(SOME_CONTEXT)) {
164 emitToken(oss, delimeter_);
167 emitToken(oss, msg.context());
173 if (!format_.want(TEXT))
return;
175 #if MESSAGEFACILITY_HEX_VERSION < 0x20201 // format changed to format_ for s67
176 format_.preambleMode =
false;
178 auto const usrMsgStart = std::next(msg.items().cbegin(), 4);
179 auto it = msg.items().cbegin();
182 if (
true || !msg.is_verbatim()) {
184 while (it != usrMsgStart) {
185 if (!it->compare(
" ") && !std::next(it)->compare(
"--")) {
190 emitToken(oss, *it++);
195 if (format_.want(NO_LINE_BREAKS))
196 emitToken(oss,
" ==> ");
198 emitToken(oss,
"",
true);
202 auto const end = msg.items().cend();
203 for (; it != end; ++it) {
210 if ((
true || !msg.is_verbatim()) && !format_.want(NO_LINE_BREAKS)) {
211 emitToken(oss,
"\n%MSG");
224 #ifndef EXTERN_C_FUNC_DECLARE_START
225 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
228 EXTERN_C_FUNC_DECLARE_START
229 auto makePlugin(
const std::string&,
const fhicl::ParameterSet& pset) {
230 return std::make_unique<mfplugins::ELFriendly>(pset);
234 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(Parameters const &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.