ELdestination.h
Go to the documentation of this file.
1 #ifndef messagefacility_MessageService_ELdestination_h
2 #define messagefacility_MessageService_ELdestination_h
3 // vim: set sw=2 expandtab :
4 
6 #include "fhiclcpp/fwd.h"
7 #include "fhiclcpp/types/Atom.h"
9 #include "fhiclcpp/types/Table.h"
13 
14 #include <bitset>
15 #include <cstddef>
16 #include <ctime>
17 #include <iosfwd>
18 #include <map>
19 #include <sstream>
20 #include <string>
21 
22 namespace mf::service {
23 
24  class ELdestination {
25  public:
26  enum flag_enum {
39  };
40 
41  struct Category {
42  struct Config {
43  ~Config();
44  Config();
45  explicit Config(fhicl::ParameterSet const& pset);
46 
47  static std::string limit_comment();
50 
54  };
55 
56  ~Category();
57  Category();
58  };
59 
60  struct CategoryParams {
61  ~CategoryParams();
63 
64  int limit_;
66  int timespan_;
67  };
68 
69  struct XidLimiter {
70  ~XidLimiter();
71  XidLimiter();
72 
74  int msgCount_{};
76 
77  int limit_;
79  int timespan_;
80  };
81 
82  struct StatsCount {
83  ~StatsCount();
84  StatsCount();
85  void add(std::string const& context, bool reactedTo);
86 
87  int n_{};
88  int aggregateN_{};
89  bool ignoredFlag_{false};
90  std::string context1_{};
91  std::string context2_{};
92  std::string contextLast_{};
93  };
94 
96  public:
97  struct Config {
98  ~Config();
99  Config();
100 
112  };
113 
116 
117  bool want(flag_enum const) const;
118  std::string timestamp(timeval const&);
119 
120  std::bitset<NFLAGS> flags;
121  std::size_t lineLength;
122 
123  private:
124  int timeMethod_{0};
125  std::string timeFmt_{};
126  };
127 
129  public:
130  struct Config {
131  ~Config();
132  Config();
133  // FIXME: I think we will want this to apply to resetLimiters() only.
135  fhicl::Name("reset"),
136  fhicl::Comment("Used for statistics destinations"),
137  false};
138  // FIXME: I think we will want this to apply to resetMsgCounters()
139  // only.
140  fhicl::Atom<bool> resetStatistics{fhicl::Name("resetStatistics"),
141  false};
142  };
143 
144  ~MsgStatistics() = delete;
145  MsgStatistics() = delete;
146  MsgStatistics(MsgStatistics const&) = delete;
147  MsgStatistics(MsgStatistics&&) = delete;
148  MsgStatistics& operator=(MsgStatistics const&) = delete;
150  };
151 
152  struct Config {
153  ~Config();
154  Config();
161  };
162 
163  virtual ~ELdestination() noexcept = default;
165  ELdestination(ELdestination const&) = delete;
166  ELdestination(ELdestination&&) = delete;
167  ELdestination& operator=(ELdestination const&) = delete;
168  ELdestination& operator=(ELdestination&&) = delete;
169 
170  // Used only by MessageLoggerScribe to disable cerr_early once startup is
171  // complete.
172  void setThreshold(ELseverityLevel sv);
173 
174  // API which may be overridden by subclasses
175  // Currently the only overrider is ELstatistics and then only log() and
176  // summary(), not finish()
177 
178  // Called only by MessageLoggerScribe::sendMsgToDests
179  // Called by MessageLoggerScribe::logMessage
180  // Called by MessageLogger::LogErrorObj
181  // Called by MaybeLogger_ dtor
182  // Called by MessageLoggerScribe dtor
183  // Called by MessageLogger::EndMessageFacility
184  // Called by global dtor of MessageLogger::mlscribe_ptr
185  virtual void log(mf::ErrorObj&);
186 
187  // Called only by MessageLoggerScribe dtor.
188  // Called at message facility shutdown.
189  virtual void finish();
190 
191  // Called only by MessageLoggerScribe::summarize()
192  // Called only by MessageLogger::LogStatistics()
193  virtual void summary();
194 
195  protected:
196  std::string summarizeContext(std::string const&);
197  void emitToken(std::ostream& os,
198  std::string const& s,
199  bool nl = false,
200  bool preambleMode = false);
201  std::string formSummary();
202 
203  // A return value of true tells the destination to not log this message.
204  // Called by ELdestination::log().
205  bool skipMsg(ELextendedID const&);
206 
207  // Called by ELdestination::summary()
208  // Called by ELstatistics::summary()
209  void resetLimiters();
210 
211  // Called by ELdestination::summary()
212  // Called by ELstatistics::summary()
213  void resetMsgCounters();
214 
215  virtual void fillPrefix(std::ostringstream&, mf::ErrorObj const& msg);
216  virtual void fillUsrMsg(std::ostringstream&, mf::ErrorObj const& msg);
217  virtual void fillSuffix(std::ostringstream&, mf::ErrorObj const& msg);
218  virtual void routePayload(std::ostringstream const&,
219  mf::ErrorObj const& msg);
220 
221  // We never call this, but artdaq mfextensions needs it.
222  virtual void flush();
223 
229  std::map<std::string const, CategoryParams> categoryParams_;
232  bool outputStatistics_{false};
233  bool updatedStats_{false};
234  bool reset_{false};
235 
236  private:
237  std::size_t charsOnLine_{};
238  };
239 
240 } // namespace mf::service
241 
242 namespace cet {
243  template <>
244  struct PluginTypeDeducer<mf::service::ELdestination> {
245  static std::string const value;
246  };
247 } // namespace cet
248 
249 #endif /* messagefacility_MessageService_ELdestination_h */
250 
251 // Local variables:
252 // mode: c++
253 // End:
fhicl::Table< MsgFormatSettings::Config > format
virtual void fillUsrMsg(std::ostringstream &, mf::ErrorObj const &msg)
bool skipMsg(ELextendedID const &)
void msg(const char *fmt,...)
Definition: message.cpp:107
fhicl::TableFragment< MsgStatistics::Config > msgStatistics
std::string string
Definition: nybbler.cc:12
void emitToken(std::ostream &os, std::string const &s, bool nl=false, bool preambleMode=false)
Coord add(Coord c1, Coord c2)
Definition: restypedef.cpp:23
ChannelGroupService::Name Name
STL namespace.
ELdestination & operator=(ELdestination const &)=delete
fhicl::OptionalDelegatedParameter categories
virtual void fillSuffix(std::ostringstream &, mf::ErrorObj const &msg)
std::map< std::string const, CategoryParams > categoryParams_
virtual void log(mf::ErrorObj &)
fhicl::Atom< std::string > dest_type
fhicl::Atom< std::string > threshold
fhicl::Atom< unsigned long long > lineLength
QTextStream & reset(QTextStream &s)
std::map< ELextendedID const, StatsCount > statsMap_
std::string summarizeContext(std::string const &)
static Config * config
Definition: config.cpp:1054
ELseverityLevel threshold_
fhicl::Atom< bool > outputStatistics
#define Comment
virtual ~ELdestination() noexcept=default
virtual void fillPrefix(std::ostringstream &, mf::ErrorObj const &msg)
MsgFormatSettings format_
void setThreshold(ELseverityLevel sv)
std::map< ELextendedID const, XidLimiter > xidLimiters_
std::string nl(std::size_t i=1)
static QCString * s
Definition: config.cpp:1042
virtual void routePayload(std::ostringstream const &, mf::ErrorObj const &msg)