ELadministrator.h
Go to the documentation of this file.
1 #ifndef messagefacility_MessageService_ELadministrator_h
2 #define messagefacility_MessageService_ELadministrator_h
3 
4 // ======================================================================
5 // ELadminstrator provides the utilities the framework uses to control
6 // logger behavior including attaching destinations. Includes the
7 // methods used by ErrorLog to evoke the logging behavior in the
8 // destinations owned by the ELadminstrator.
9 // ======================================================================
10 
11 #include "cetlib/exempt_ptr.h"
12 #include "cetlib/propagate_const.h"
17 
18 #include <array>
19 #include <map>
20 #include <memory>
21 #include <type_traits>
22 #include <utility>
23 
24 namespace mf {
25  namespace service {
26  class MessageLoggerScribe;
27 
28  class ELadministrator;
29  }
30 }
31 
33  friend ::mf::service::MessageLoggerScribe;
34 
35 public:
37  std::map<std::string, cet::propagate_const<std::unique_ptr<ELdestination>>>;
38 
39  void log(ErrorObj& msg);
40 
41  ELadministrator(ELadministrator const&) = delete;
42  ELadministrator& operator=(ELadministrator const&) = delete;
43 
44  ELadministrator(ELadministrator&&) = delete;
46 
47  // --- get/set fundamental properties:
48  //
50  void
52  {
53  highSeverity_ = sev;
54  }
55 
58 
59  bool hasDestination(std::string const&) const;
60 
61  // --- handle severity information:
62  //
64  int severityCount(ELseverityLevel sev) const;
65  int severityCount(ELseverityLevel from, ELseverityLevel to) const;
68  void resetSeverityCount(); // reset all
69 
70  // --- apply the following actions to all attached destinations:
71  //
72  void finish();
73 
74  std::string const& application() const;
78  std::string const& hostname() const;
79  std::string const& hostaddr() const;
80  long pid() const;
81 
82  void
83  incrementSeverityCount(int const sev)
84  {
85  ++severityCounts_[sev];
86  }
87 
88  // --- furnish/recall destinations:
89  //
90  template <typename DEST>
92  attach(std::string const& outputId, std::unique_ptr<DEST>&& dest)
93  {
94  return *(destinations_[outputId] = std::move(dest));
95  // If you don't like the above, an alternative is something equivalent to:
96  // return *destinations_.emplace(outputId, std::move(dest)).first->second;
97  }
98 
99 private:
100  ELadministrator(std::string const& applicationName);
101 
102  std::array<int, ELseverityLevel::nLevels> severityCounts_{
103  {0}}; // fill by aggregation
105  void updateMsg_(ErrorObj& msg) const;
106 
110  long pid_{};
111 
113 
114  template <typename F>
115  void
117  {
118  for (auto& pr : destinations_)
119  f(*pr.second);
120  }
121 
122 }; // ELadministrator
123 
124 inline auto
126  -> destination_collection_t const&
127 {
128  return destinations_;
129 }
130 
131 inline auto
133 {
134  return destinations_;
135 }
136 
137 inline std::string const&
139 {
140  return hostname_;
141 }
142 
143 inline std::string const&
145 {
146  return hostaddr_;
147 }
148 
149 inline std::string const&
151 {
152  return application_;
153 }
154 
155 inline long
157 {
158  return pid_;
159 }
160 
161 inline mf::ELseverityLevel
163 {
164  return highSeverity_;
165 }
166 
167 inline void
169 {
170  for_all_destinations([](auto& d) { d.finish(); });
171 }
172 
173 #endif /* messagefacility_MessageService_ELadministrator_h */
174 
175 // Local Variables:
176 // mode: c++
177 // End:
std::string string
Definition: nybbler.cc:12
std::enable_if_t< std::is_base_of< ELdestination, DEST >::value, ELdestination & > attach(std::string const &outputId, std::unique_ptr< DEST > &&dest)
bool hasDestination(std::string const &) const
void setApplication(std::string const &application)
std::string const & hostname() const
std::map< std::string, cet::propagate_const< std::unique_ptr< ELdestination >>> destination_collection_t
destination_collection_t const & destinations() const
int severityCount(ELseverityLevel sev) const
void updateMsg_(ErrorObj &msg) const
ELseverityLevel exitThreshold() const
destination_collection_t destinations_
ELadministrator & operator=(ELadministrator const &)=delete
ELseverityLevel highSeverity() const
ELseverityLevel abortThreshold() const
ELadministrator(ELadministrator const &)=delete
f
Make Macro files for next generation.
std::array< int, ELseverityLevel::nLevels > severityCounts_
std::string const & hostaddr() const
void incrementSeverityCount(int const sev)
ELseverityLevel checkSeverity()
void setHighSeverity(ELseverityLevel const sev)
std::string const & application() const