LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
ErrorObj.h
Go to the documentation of this file.
1 #ifndef messagefacility_Utilities_ErrorObj_h
2 #define messagefacility_Utilities_ErrorObj_h
3 // vim: set sw=2 expandtab :
4 
7 
8 #include <list>
9 #include <sstream>
10 #include <string>
11 #include <type_traits>
12 
13 #include <sys/time.h>
14 
15 namespace mf {
16 
17  class ErrorLog;
18 
19  // Note: This class is virtual because it is user-visible and customizable.
20  class ErrorObj {
21 
22  public:
23  virtual ~ErrorObj();
24  ErrorObj() = delete;
25  ErrorObj(ELseverityLevel const sev,
26  std::string const& category,
27  bool verbatim = false,
28  std::string const& filename = "",
29  int lineNumber = 0);
30  ErrorObj(ErrorObj const&);
31 
32  int serial() const;
33  ELextendedID const& xid() const;
34  std::string const& idOverflow() const;
35  timeval timestamp() const;
36  std::list<std::string> const& items() const;
37  bool reactedTo() const;
38 
39  // Return concatenated items, the full text of the message.
40  std::string fullText() const;
41 
42  // Note: Obsolete! Remove me when user code migrated.
43  std::string const& context() const;
44  std::string const& iteration() const;
45  bool is_verbatim() const;
46  std::string const& filename() const;
47  int lineNumber() const;
48 
49  // mine
50  virtual void setTimestamp(timeval const&);
51  // Note: Obsolete! Remove me when user code migrated.
52  virtual void setContext(std::string const&);
53  virtual void setIteration(std::string const&);
54 
55  // part of xid
56  virtual void setSeverity(ELseverityLevel const);
57  virtual void setID(std::string const&);
58  virtual void setModule(std::string const&);
59  virtual void setSubroutine(std::string const&);
60 
61  // Per-message overrides for the global settings, part of xid
62  virtual void setHostName(std::string const&);
63  virtual void setHostAddr(std::string const&);
64  virtual void setApplication(std::string const&);
65  virtual void setPID(long);
66 
67  ErrorObj& operator<<(std::ostream& (*f)(std::ostream&));
68  ErrorObj& operator<<(std::ios_base& (*f)(std::ios_base&));
69 
70  // Explicit function for char const* to avoid unnecessary
71  // instantiations of char const[] types.
72  ErrorObj& opltlt(char const*);
73 
74  template <class T>
75  ErrorObj& opltlt(T const&);
76 
77  virtual ErrorObj& eo_emit(std::string const&);
78 
79  virtual void clear();
80  virtual void set(ELseverityLevel const, std::string const& id);
81  virtual void setReactedTo(bool);
82 
83  private:
84  int serial_{};
86  std::string idOverflow_{};
87  timeval timestamp_{0, 0};
88  std::list<std::string> items_{};
89  bool reactedTo_{false};
90  std::string iteration_{};
91  std::ostringstream oss_{};
92  bool verbatim_{false};
93  std::string filename_{};
94  int lineNumber_{};
95  };
96 
97  template <class T>
98  ErrorObj&
99  ErrorObj::opltlt(T const& t)
100  {
101  oss_.str({});
102  oss_ << t;
103  if (!oss_.str().empty()) {
104  eo_emit(oss_.str());
105  }
106  return *this;
107  }
108 
109  //
110  ErrorObj& operator<<(ErrorObj& e, char const* s);
111 
112  // Force conversion of char arrays to string.
113  template <class T>
114  ErrorObj&
115  operator<<(ErrorObj& e, T const& t)
116  {
117  return e.opltlt(t);
118  }
119 
120 } // namespace mf
121 
122 #endif /* messagefacility_Utilities_ErrorObj_h */
123 
124 // Local variables:
125 // mode: c++
126 // End:
int lineNumber() const
Definition: ErrorObj.cc:126
virtual ErrorObj & eo_emit(std::string const &)
Definition: ErrorObj.cc:207
virtual void setID(std::string const &)
Definition: ErrorObj.cc:141
Float_t s
Definition: plot.C:23
bool verbatim_
Definition: ErrorObj.h:92
timeval timestamp() const
Definition: ErrorObj.cc:73
timeval timestamp_
Definition: ErrorObj.h:87
std::string idOverflow_
Definition: ErrorObj.h:86
virtual void setModule(std::string const &)
Definition: ErrorObj.cc:151
virtual void setPID(long)
Definition: ErrorObj.cc:201
virtual void setTimestamp(timeval const &)
Definition: ErrorObj.cc:241
virtual void setHostName(std::string const &)
Definition: ErrorObj.cc:183
std::string filename_
Definition: ErrorObj.h:93
std::list< std::string > const & items() const
Definition: ErrorObj.cc:79
std::string const & context() const
Definition: ErrorObj.cc:98
bool is_verbatim() const
Definition: ErrorObj.cc:91
TFile f
Definition: plotHisto.C:6
int serial_
Definition: ErrorObj.h:84
virtual ~ErrorObj()
Definition: ErrorObj.cc:20
std::string const & iteration() const
Definition: ErrorObj.cc:104
std::string const & idOverflow() const
Definition: ErrorObj.cc:67
virtual void clear()
Definition: ErrorObj.cc:218
ErrorObj & operator<<(std::ostream &(*f)(std::ostream &))
Definition: ErrorObj.cc:247
int lineNumber_
Definition: ErrorObj.h:94
bool reactedTo_
Definition: ErrorObj.h:89
ELextendedID const & xid() const
Definition: ErrorObj.cc:61
virtual void setSeverity(ELseverityLevel const)
Definition: ErrorObj.cc:132
std::string const & filename() const
Definition: ErrorObj.cc:120
virtual void setContext(std::string const &)
Definition: ErrorObj.cc:158
ELextendedID xid_
Definition: ErrorObj.h:85
virtual void setHostAddr(std::string const &)
Definition: ErrorObj.cc:189
std::string fullText() const
Definition: ErrorObj.cc:110
virtual void setApplication(std::string const &)
Definition: ErrorObj.cc:195
int serial() const
Definition: ErrorObj.cc:55
ErrorObj & opltlt(char const *)
Definition: ErrorObj.cc:263
ErrorObj()=delete
bool reactedTo() const
Definition: ErrorObj.cc:85
std::string iteration_
Definition: ErrorObj.h:90
std::ostringstream oss_
Definition: ErrorObj.h:91
virtual void setSubroutine(std::string const &)
Definition: ErrorObj.cc:170
virtual void setReactedTo(bool)
Definition: ErrorObj.cc:177
virtual void setIteration(std::string const &)
Definition: ErrorObj.cc:164
Float_t e
Definition: plot.C:34
std::list< std::string > items_
Definition: ErrorObj.h:88