LibPkg
log.h
Go to the documentation of this file.
1 // This file is part of LibPkg.
2 // Copyright � 2003-2005 Graham Shaw.
3 // Copyright � 2013 Alan Buckley
4 // Distribution and use are subject to the GNU Lesser General Public License,
5 // a copy of which may be found in the file !LibPkg.Copyright.
6 
7 #ifndef LIBPKG_LOG
8 #define LIBPKG_LOG
9 
10 #include <string>
11 #include <vector>
12 #include <ostream>
13 
14 namespace pkg {
15 
19  enum LogCode {
42  LOG_TRACE = 0x20000,
123  };
124 
128  class log_entry
129  {
131  LogCode _code;
133  int _when;
135  char *_param1;
137  char *_param2;
138 
139  public:
143  log_entry();
144 
148  log_entry(const log_entry &other);
149 
151  ~log_entry();
152 
156  log_entry &operator=(const log_entry &other);
157 
165  log_entry(LogCode code, const char *param1 = 0, const char *param2 = 0);
166 
172  int code() const { return _code; }
173 
179  int type() const { return (_code >> 16); }
180 
186  int sub_code() const { return (_code & 0xFFFF); }
187 
193  int when() const { return _when; }
194 
200  std::string when_text() const;
201 
207  std::string text() const;
208  };
209 
213  class log
214  {
216  std::vector<log_entry> _entries;
218  unsigned int _counts[2];
220  bool _bad;
221 
222  public:
226  log();
227 
233  bool bad() const { return _bad; }
234 
242  void message(LogCode code, const char *param1 = 0, const char *param2 = 0);
243 
250  void message(LogCode code, const std::string &param) { message(code, param.c_str()); }
258  void message(LogCode code, const std::string &param1, const std::string &param2) { message(code, param1.c_str(), param2.c_str()); }
259 
261  typedef std::vector<log_entry>::const_iterator const_iterator;
263  const_iterator begin() const { return _entries.begin(); }
265  const_iterator end() const { return _entries.end(); }
267  unsigned int size() const { return _entries.size(); }
269  unsigned int errors() const { return _counts[0]; }
271  unsigned int warnings() const { return _counts[1]; }
272 
274  const log_entry &operator[](int index) const { return _entries[index]; }
276  const log_entry &entry(int index) const { return _entries[index]; }
277 
279  friend std::ostream &operator<<(std::ostream &stream, const log &olog);
280  };
281 
282  std::ostream &operator<<(std::ostream &stream, const log &olog);
283 };
284 
285 #endif
Definition: log.h:70
Definition: log.h:66
Definition: log.h:82
Definition: log.h:100
Definition: log.h:87
std::ostream & operator<<(std::ostream &out, const component &comp)
Write component record to output stream.
Definition: component.cc:179
int sub_code() const
Log entry sub code.
Definition: log.h:186
~log_entry()
Destroy entry freeing memory.
Definition: log.cc:171
const_iterator begin() const
Iterator to first log entry.
Definition: log.h:263
log_entry()
Construct uninitialised log entry.
Definition: log.cc:159
std::string when_text() const
Time of log entry as text.
Definition: log.cc:197
void message(LogCode code, const std::string &param1, const std::string &param2)
Add a new entry to the log from two standard strings.
Definition: log.h:258
Definition: log.h:118
Definition: log.h:119
void message(LogCode code, const std::string &param)
Add a new entry to the log from a standard string.
Definition: log.h:250
std::vector< log_entry >::const_iterator const_iterator
Iterator type for the log entries.
Definition: log.h:261
Definition: log.h:71
unsigned int errors() const
Number of errors.
Definition: log.h:269
Definition: log.h:68
Definition: log.h:91
Definition: log.h:76
Definition: log.h:97
The namespace used to hold the package management library.
Definition: auto_dir.cc:12
int type() const
Log entry type.
Definition: log.h:179
Definition: log.h:25
Definition: log.h:69
Definition: log.h:89
unsigned int warnings() const
Number of warnings.
Definition: log.h:271
const log_entry & entry(int index) const
Return entry for a given index.
Definition: log.h:276
Definition: log.h:60
Definition: log.h:105
Definition: log.h:75
Definition: log.h:67
Definition: log.h:90
log_entry & operator=(const log_entry &other)
Assignment.
Definition: log.cc:177
Definition: log.h:42
Definition: log.h:23
Definition: log.h:121
Definition: log.h:103
Definition: log.h:73
Definition: log.h:102
Definition: log.h:44
const log_entry & operator[](int index) const
Return entry for a given index.
Definition: log.h:274
Definition: log.h:112
Definition: log.h:50
Definition: log.h:96
Definition: log.h:104
Definition: log.h:77
Definition: log.h:53
Definition: log.h:27
Definition: log.h:57
Definition: log.h:120
Definition: log.h:62
Definition: log.h:54
int when() const
Time since midnight of log entry.
Definition: log.h:193
Definition: log.h:84
Definition: log.h:94
Definition: log.h:95
Definition: log.h:65
Class to log actions that occur in LibPkg.
Definition: log.h:213
Definition: log.h:88
Definition: log.h:51
Definition: log.h:109
Definition: log.h:28
bool bad() const
The log failed to add one or more items.
Definition: log.h:233
Definition: log.h:101
Definition: log.h:85
std::string text() const
Description of this log entry.
Definition: log.cc:212
Definition: log.h:43
Definition: log.h:99
Definition: log.h:64
Definition: log.h:56
Definition: log.h:79
Definition: log.h:20
Definition: log.h:74
Definition: log.h:61
Definition: log.h:63
Definition: log.h:106
int code() const
Log entry error code.
Definition: log.h:172
Definition: log.h:98
unsigned int size() const
Total number of entries.
Definition: log.h:267
const_iterator end() const
Iterator to last log entry.
Definition: log.h:265
Definition: log.h:30
A class to represent one log entry.
Definition: log.h:128
LogCode
An enumeration of all the items that can be logged.
Definition: log.h:19
Definition: log.h:49
Definition: log.h:108
Definition: log.h:122

Reference Manual LibPkg Version 0.6.1 (28 Jan 2015)