LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
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 
5 #include "cetlib/PluginTypeDeducer.h"
7 #include "fhiclcpp/types/Atom.h"
10 #include "fhiclcpp/types/Table.h"
14 
15 #include <bitset>
16 #include <cstddef>
17 #include <map>
18 #include <ostream>
19 #include <sstream>
20 #include <string>
21 
22 namespace mf {
23  namespace service {
24 
25  class ELdestination {
26 
27  // Types
28  public:
29  // Allowed values of MsgFormatSettings::flags
30  enum flag_enum {
43  };
44 
45  struct Category {
46 
47  struct Config {
48 
49  ~Config();
50  Config();
51  explicit Config(fhicl::ParameterSet const& pset);
52 
53  static std::string limit_comment();
54  static std::string reportEvery_comment();
55  static std::string timespan_comment();
56 
60  };
61 
62  ~Category();
63  Category();
64  };
65 
66  struct CategoryParams {
67 
68  ~CategoryParams();
70 
71  int limit_;
73  int timespan_;
74  };
75 
76  struct XidLimiter {
77 
78  ~XidLimiter();
79  XidLimiter();
80 
82  int msgCount_{};
84 
85  int limit_;
87  int timespan_;
88  };
89 
90  struct StatsCount {
91 
92  ~StatsCount();
93  StatsCount();
94  void add(std::string const& context, bool reactedTo);
95 
96  int n_{};
97  int aggregateN_{};
98  bool ignoredFlag_{false};
99  std::string context1_{};
100  std::string context2_{};
101  std::string contextLast_{};
102  };
103 
105 
106  // Configuration
107  public:
108  struct Config {
109 
110  ~Config();
111  Config();
112 
124  };
125 
126  // Special Member Functions
127  public:
129  MsgFormatSettings(Config const& config);
130 
131  // API
132  public:
133  bool want(flag_enum const) const;
134  std::string timestamp(timeval const&);
135 
136  // My Data
137  public:
138  std::bitset<NFLAGS> flags;
139  std::size_t lineLength;
140 
141  // My Data
142  private:
143  int timeMethod_{0};
144  std::string timeFmt_{};
145  };
146 
148 
149  // Configuration
150  public:
151  struct Config {
152  ~Config();
153  Config();
154  // FIXME: I think we will want this to apply to resetLimiters() only.
156  fhicl::Name("reset"),
157  fhicl::Comment("Used for statistics destinations"),
158  false};
159  // FIXME: I think we will want this to apply to resetMsgCounters()
160  // only.
161  fhicl::Atom<bool> resetStatistics{fhicl::Name("resetStatistics"),
162  false};
163  };
164 
165  // Special Member Functions
166  public:
167  ~MsgStatistics() = delete;
168  MsgStatistics() = delete;
169  MsgStatistics(MsgStatistics const&) = delete;
170  MsgStatistics(MsgStatistics&&) = delete;
171  MsgStatistics& operator=(MsgStatistics const&) = delete;
173  };
174 
175  // Configuration
176  public:
177  struct Config {
178  ~Config();
179  Config();
186  };
187 
188  // Special Member Functions
189  public:
190  virtual ~ELdestination() noexcept = default;
191  ELdestination(Config const&);
192  ELdestination(ELdestination const&) = delete;
193  ELdestination(ELdestination&&) = delete;
194  ELdestination& operator=(ELdestination const&) = delete;
195  ELdestination& operator=(ELdestination&&) = delete;
196 
197  // API
198  public:
199  // Used only by MessageLoggerScribe to disable
200  // cerr_early once startup is complete.
201  void setThreshold(ELseverityLevel sv);
202 
203  // API which may be overridden by subclasses
204  // Currently the only overrider is ELstatistics
205  // and then only log() and summary(), not finish()
206  public:
207  // Called only by MessageLoggerScribe::sendMsgToDests
208  // Called by MessageLoggerScribe::logMessage
209  // Called by MessageLogger::LogErrorObj
210  // Called by MaybeLogger_ dtor
211  // Called by MessageLoggerScribe dtor
212  // Called by MessageLogger::EndMessageFacility
213  // Called by global dtor of MessageLogger::mlscribe_ptr
214  virtual void log(mf::ErrorObj&);
215 
216  // Called only by MessageLoggerScribe dtor.
217  // Called at message facility shutdown.
218  virtual void finish();
219 
220  // Called only by MessageLoggerScribe::summarize()
221  // Called only by MessageLogger::LogStatistics()
222  virtual void summary();
223 
224  // API provided to subclasses
225  protected:
226  std::string summarizeContext(std::string const&);
227  void emitToken(std::ostream& os,
228  std::string const& s,
229  bool nl = false,
230  bool preambleMode = false);
231  std::string formSummary();
232 
233  // A return value of true tells the destination
234  // to not log this message.
235  // Called by ELdestination::log().
236  bool skipMsg(ELextendedID const&);
237 
238  // Called by ELdestination::summary()
239  // Called by ELstatistics::summary()
240  void resetLimiters();
241 
242  // Called by ELdestination::summary()
243  // Called by ELstatistics::summary()
244  void resetMsgCounters();
245 
246  // API to be provided by subclasses
247  protected:
248  virtual void fillPrefix(std::ostringstream&, mf::ErrorObj const& msg);
249  virtual void fillUsrMsg(std::ostringstream&, mf::ErrorObj const& msg);
250  virtual void fillSuffix(std::ostringstream&, mf::ErrorObj const& msg);
251  virtual void routePayload(std::ostringstream const&,
252  mf::ErrorObj const& msg);
253 
254  // We never call this, but artdaq mfextensions needs it.
255  virtual void flush();
256 
257  // Member Data for subclasses
258  protected:
264  std::map<std::string const, CategoryParams> categoryParams_;
267  bool outputStatistics_{false};
268  bool updatedStats_{false};
269  bool reset_{false};
270 
271  // Member Data for myself
272  private:
273  std::size_t charsOnLine_{};
274  };
275 
276  } // namespace service
277 } // namespace mf
278 
279 namespace cet {
280 
281  template <>
282  struct PluginTypeDeducer<mf::service::ELdestination> {
283  static std::string const value;
284  };
285 
286 } // namespace cet
287 
288 #endif /* messagefacility_MessageService_ELdestination_h */
289 
290 // Local variables:
291 // mode: c++
292 // End:
fhicl::Table< MsgFormatSettings::Config > format
Float_t s
Definition: plot.C:23
virtual void fillUsrMsg(std::ostringstream &, mf::ErrorObj const &msg)
bool skipMsg(ELextendedID const &)
fhicl::TableFragment< MsgStatistics::Config > msgStatistics
void emitToken(std::ostream &os, std::string const &s, bool nl=false, bool preambleMode=false)
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
std::map< ELextendedID const, StatsCount > statsMap_
std::string summarizeContext(std::string const &)
ELseverityLevel threshold_
fhicl::Atom< bool > outputStatistics
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)
virtual void routePayload(std::ostringstream const &, mf::ErrorObj const &msg)