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;
37 fhicl::Atom<std::string> delimiter = fhicl::Atom<std::string>{
38 fhicl::Name{
"field_delimiter"},
39 fhicl::Comment{
"String to print between each message field"},
" "};
56 virtual void fillPrefix(std::ostringstream& o,
const ErrorObj& e)
override;
62 virtual void fillUsrMsg(std::ostringstream& o,
const ErrorObj& e)
override;
68 virtual void fillSuffix(std::ostringstream& o,
const ErrorObj& e)
override;
71 std::string delimeter_;
83 : ELostreamOutput(pset().elOstrConfig(), cet::ostream_handle{std::cout},
false), delimeter_(pset().delimiter()) {}
93 #if MESSAGEFACILITY_HEX_VERSION < 0x20201 // format changed to format_ for s67
94 format_.preambleMode =
true;
97 auto const& xid = msg.xid();
100 auto app = xid.application();
101 auto module = xid.module();
102 auto subroutine = xid.subroutine();
103 std::replace(
id.begin(),
id.end(),
' ',
'-');
104 std::replace(app.begin(), app.end(),
' ',
'-');
105 std::replace(module.begin(), module.end(),
' ',
'-');
106 std::replace(subroutine.begin(), subroutine.end(),
' ',
'-');
108 emitToken(oss,
"%MSG");
109 emitToken(oss, xid.severity().getSymbol());
110 emitToken(oss, delimeter_);
112 emitToken(oss, msg.idOverflow());
114 emitToken(oss, delimeter_);
118 if (format_.want(SERIAL)) {
119 std::ostringstream s;
121 emitToken(oss,
"[serial #" + s.str() +
"]");
122 emitToken(oss, delimeter_);
127 bool needAspace =
true;
128 if (format_.want(EPILOGUE_SEPARATE)) {
129 if (module.length() + subroutine.length() > 0) {
130 emitToken(oss,
"\n");
132 }
else if (format_.want(TIMESTAMP) && !format_.want(TIME_SEPARATE)) {
133 emitToken(oss,
"\n");
137 if (format_.want(MODULE) && (module.length() > 0)) {
139 emitToken(oss, delimeter_);
142 emitToken(oss, module +
" ");
144 if (format_.want(SUBROUTINE) && (subroutine.length() > 0)) {
146 emitToken(oss, delimeter_);
149 emitToken(oss, subroutine +
"()");
150 emitToken(oss, delimeter_);
155 if (format_.want(TIMESTAMP)) {
156 if (format_.want(TIME_SEPARATE)) {
157 emitToken(oss,
"\n");
161 emitToken(oss, delimeter_);
164 emitToken(oss, format_.timestamp(msg.timestamp()));
165 emitToken(oss, delimeter_);
170 if (format_.want(SOME_CONTEXT)) {
172 emitToken(oss, delimeter_);
175 emitToken(oss, msg.context());
181 if (!format_.want(TEXT))
return;
183 #if MESSAGEFACILITY_HEX_VERSION < 0x20201 // format changed to format_ for s67
184 format_.preambleMode =
false;
186 auto const usrMsgStart = std::next(msg.items().cbegin(), 4);
187 auto it = msg.items().cbegin();
190 if (
true || !msg.is_verbatim()) {
192 while (it != usrMsgStart) {
193 if (!it->compare(
" ") && !std::next(it)->compare(
"--")) {
198 emitToken(oss, *it++);
203 if (format_.want(NO_LINE_BREAKS))
204 emitToken(oss,
" ==> ");
206 emitToken(oss,
"",
true);
210 auto const end = msg.items().cend();
211 for (; it != end; ++it) {
218 if ((
true || !msg.is_verbatim()) && !format_.want(NO_LINE_BREAKS)) {
219 emitToken(oss,
"\n%MSG");
232 #ifndef EXTERN_C_FUNC_DECLARE_START
233 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
236 EXTERN_C_FUNC_DECLARE_START
237 auto makePlugin(
const std::string&,
const fhicl::ParameterSet& pset) {
238 return std::make_unique<mfplugins::ELFriendly>(pset);
242 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
fhicl::WrappedTable< Config > Parameters
Used for ParameterSet validation.
virtual void fillUsrMsg(std::ostringstream &o, const ErrorObj &e) override
Fill the "User Message" portion of the message.
fhicl::TableFragment< ELostreamOutput::Config > elOstrConfig
Configuration parameters for ELostreamOutput.
virtual void fillPrefix(std::ostringstream &o, const ErrorObj &e) override
Fill the "Prefix" portion of the message.
Configuration Parameters for ELFriendly.