1 #include "cetlib/PluginTypeDeducer.h"
2 #include "cetlib/ostream_handle.h"
3 #include "fhiclcpp/ParameterSet.h"
5 #include "messagefacility/MessageService/ELdestination.h"
6 #include "messagefacility/MessageService/ELostreamOutput.h"
7 #include "messagefacility/Utilities/ELseverityLevel.h"
8 #if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
9 # include "messagefacility/MessageService/ELcontextSupplier.h"
10 # include "messagefacility/MessageLogger/MessageDrop.h"
12 #include "messagefacility/Utilities/exception.h"
22 using namespace mf::service;
23 using mf::ELseverityLevel;
31 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
34 fhicl::TableFragment<ELostreamOutput::Config> elOstrConfig;
35 fhicl::Atom<std::string> delimiter{ fhicl::Name{
"field_delimiter" },fhicl::Comment{
"String to print between each message field" },
" " };
37 using Parameters = fhicl::WrappedTable<Config>;
40 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
46 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
47 virtual void fillPrefix(std::ostringstream&,
const ErrorObj&)
override;
49 virtual void fillPrefix(std::ostringstream&,
const ErrorObj&,
const ELcontextSupplier&)
override;
51 virtual void fillUsrMsg(std::ostringstream&,
const ErrorObj&)
override;
52 virtual void fillSuffix(std::ostringstream&,
const ErrorObj&)
override;
55 std::string delimeter_;
67 #if MESSAGEFACILITY_HEX_VERSION < 0x20103 // v2_01_03 is s58, pre v2_01_03 is s50
68 ELFriendly::ELFriendly(
const fhicl::ParameterSet& pset)
69 : ELostreamOutput(pset, cet::ostream_handle{ std::cout },
false)
70 , delimeter_(pset.get<std::string>(
"field_delimeter",
" "))
72 ELFriendly::ELFriendly(Parameters
const& pset)
73 : ELostreamOutput(pset().elOstrConfig(), cet::ostream_handle{ std::cout },
false)
74 , delimeter_(pset().delimiter())
81 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
82 void ELFriendly::fillPrefix(std::ostringstream& oss,
const ErrorObj& msg)
84 void ELFriendly::fillPrefix(std::ostringstream& oss,
const ErrorObj& msg, ELcontextSupplier
const& contextSupplier)
91 format.preambleMode =
true;
93 auto const& xid = msg.xid();
95 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
97 auto app = xid.application();
98 auto module = xid.module();
99 auto subroutine = xid.subroutine();
102 auto app = xid.application;
103 auto process = xid.process;
104 auto module = xid.module;
105 auto subroutine = xid.subroutine;
106 std::replace(process.begin(), process.end(),
' ',
'-');
107 # define emitToken emit
109 std::replace(
id.begin(),
id.end(),
' ',
'-');
110 std::replace(app.begin(), app.end(),
' ',
'-');
111 std::replace(module.begin(), module.end(),
' ',
'-');
112 std::replace(subroutine.begin(), subroutine.end(),
' ',
'-');
114 emitToken(oss,
"%MSG");
115 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
116 emitToken(oss, xid.severity().getSymbol());
118 emit(oss, xid.severity.getSymbol());
120 emitToken(oss, delimeter_);
122 emitToken(oss, msg.idOverflow());
124 emitToken(oss, delimeter_);
128 if (format.want(SERIAL)) {
129 std::ostringstream s;
131 emitToken(oss,
"[serial #" + s.str() +
"]");
132 emitToken(oss, delimeter_);
137 bool needAspace =
true;
138 if (format.want(EPILOGUE_SEPARATE)) {
139 if (module.length() + subroutine.length() > 0) {
140 emitToken(oss,
"\n");
143 else if (format.want(TIMESTAMP) && !format.want(TIME_SEPARATE)) {
144 emitToken(oss,
"\n");
148 if (format.want(MODULE) && (module.length() > 0)) {
150 emitToken(oss, delimeter_);
153 emitToken(oss, module +
" ");
155 if (format.want(SUBROUTINE) && (subroutine.length() > 0)) {
157 emitToken(oss, delimeter_);
160 emitToken(oss, subroutine +
"()");
161 emitToken(oss, delimeter_);
166 if (format.want(TIMESTAMP)) {
167 if (format.want(TIME_SEPARATE)) {
168 emitToken(oss,
"\n");
172 emitToken(oss, delimeter_);
175 emitToken(oss, format.timestamp(msg.timestamp()));
176 emitToken(oss, delimeter_);
181 if (format.want(SOME_CONTEXT)) {
183 emitToken(oss, delimeter_);
186 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
187 emitToken(oss, msg.context());
189 if (format.want(FULL_CONTEXT)) {
190 emit(oss, contextSupplier.fullContext());
193 emit(oss, contextSupplier.context());
202 void ELFriendly::fillUsrMsg(std::ostringstream& oss, ErrorObj
const& msg)
204 if (!format.want(TEXT))
return;
206 format.preambleMode =
false;
207 auto const usrMsgStart = std::next(msg.items().cbegin(), 4);
208 auto it = msg.items().cbegin();
211 if (
true || !msg.is_verbatim()) {
214 while (it != usrMsgStart) {
215 if (!it->compare(
" ") && !std::next(it)->compare(
"--")) {
221 emitToken(oss, *it++);
226 if (format.want(NO_LINE_BREAKS)) emitToken(oss,
" ==> ");
227 else emitToken(oss,
"",
true);
231 auto const end = msg.items().cend();
232 for (; it != end; ++it) {
240 void ELFriendly::fillSuffix(std::ostringstream& oss, ErrorObj
const& msg)
242 if ((
true || !msg.is_verbatim()) && !format.want(NO_LINE_BREAKS)) {
243 emitToken(oss,
"\n%MSG");
260 auto makePlugin(
const std::string&,
261 const fhicl::ParameterSet& pset)
263 return std::make_unique<mfplugins::ELFriendly>(pset);
267 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)
Parser-Friendly Message Facility destination plugin