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;
18 using mf::ELseverityLevel;
33 fhicl::Atom<std::string> delimiter = fhicl::Atom<std::string>{
34 fhicl::Name{
"field_delimiter"}, fhicl::Comment{
"String to print between each message field"},
" "};
51 virtual void fillPrefix(std::ostringstream& o,
const ErrorObj& e)
override;
57 virtual void fillUsrMsg(std::ostringstream& o,
const ErrorObj& e)
override;
63 virtual void fillSuffix(std::ostringstream& o,
const ErrorObj& e)
override;
66 std::string delimeter_;
78 : ELostreamOutput(pset().elOstrConfig(), cet::ostream_handle{std::cout},
false), delimeter_(pset().delimiter()) {}
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 auto const usrMsgStart = std::next(msg.items().cbegin(), 4);
176 auto it = msg.items().cbegin();
179 if (
true || !msg.is_verbatim()) {
181 while (it != usrMsgStart) {
182 if (!it->compare(
" ") && !std::next(it)->compare(
"--")) {
187 emitToken(oss, *it++);
192 if (format_.want(NO_LINE_BREAKS))
193 emitToken(oss,
" ==> ");
195 emitToken(oss,
"",
true);
199 auto const end = msg.items().cend();
200 for (; it != end; ++it) {
207 if ((
true || !msg.is_verbatim()) && !format_.want(NO_LINE_BREAKS)) {
208 emitToken(oss,
"\n%MSG");
221 #ifndef EXTERN_C_FUNC_DECLARE_START
222 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
225 EXTERN_C_FUNC_DECLARE_START
226 auto makePlugin(
const std::string&,
const fhicl::ParameterSet& pset) {
227 return std::make_unique<mfplugins::ELFriendly>(pset);
231 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.