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,
125  };
126 
130  class log_entry
131  {
133  LogCode _code;
135  int _when;
137  char *_param1;
139  char *_param2;
140 
141  public:
145  log_entry();
146 
150  log_entry(const log_entry &other);
151 
153  ~log_entry();
154 
158  log_entry &operator=(const log_entry &other);
159 
167  log_entry(LogCode code, const char *param1 = 0, const char *param2 = 0);
168 
174  int code() const { return _code; }
175 
181  int type() const { return (_code >> 16); }
182 
188  int sub_code() const { return (_code & 0xFFFF); }
189 
195  int when() const { return _when; }
196 
202  std::string when_text() const;
203 
209  std::string text() const;
210  };
211 
215  class log
216  {
218  std::vector<log_entry> _entries;
220  unsigned int _counts[2];
222  bool _bad;
223 
224  public:
228  log();
229 
235  bool bad() const { return _bad; }
236 
244  void message(LogCode code, const char *param1 = 0, const char *param2 = 0);
245 
252  void message(LogCode code, const std::string &param) { message(code, param.c_str()); }
260  void message(LogCode code, const std::string &param1, const std::string &param2) { message(code, param1.c_str(), param2.c_str()); }
261 
263  typedef std::vector<log_entry>::const_iterator const_iterator;
265  const_iterator begin() const { return _entries.begin(); }
267  const_iterator end() const { return _entries.end(); }
269  unsigned int size() const { return _entries.size(); }
271  unsigned int errors() const { return _counts[0]; }
273  unsigned int warnings() const { return _counts[1]; }
274 
276  const log_entry &operator[](int index) const { return _entries[index]; }
278  const log_entry &entry(int index) const { return _entries[index]; }
279 
281  friend std::ostream &operator<<(std::ostream &stream, const log &olog);
282  };
283 
284  std::ostream &operator<<(std::ostream &stream, const log &olog);
285 };
286 
287 #endif
Definition: log.h:70
Definition: log.h:66
Definition: log.h:83
Definition: log.h:102
Definition: log.h:89
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:188
~log_entry()
Destroy entry freeing memory.
Definition: log.cc:173
const_iterator begin() const
Iterator to first log entry.
Definition: log.h:265
log_entry()
Construct uninitialised log entry.
Definition: log.cc:161
std::string when_text() const
Time of log entry as text.
Definition: log.cc:199
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:260
Definition: log.h:120
Definition: log.h:121
void message(LogCode code, const std::string &param)
Add a new entry to the log from a standard string.
Definition: log.h:252
std::vector< log_entry >::const_iterator const_iterator
Iterator type for the log entries.
Definition: log.h:263
Definition: log.h:71
unsigned int errors() const
Number of errors.
Definition: log.h:271
Definition: log.h:68
Definition: log.h:93
Definition: log.h:77
Definition: log.h:99
The namespace used to hold the package management library.
Definition: auto_dir.cc:12
int type() const
Log entry type.
Definition: log.h:181
Definition: log.h:25
Definition: log.h:69
Definition: log.h:91
unsigned int warnings() const
Number of warnings.
Definition: log.h:273
const log_entry & entry(int index) const
Return entry for a given index.
Definition: log.h:278
Definition: log.h:60
Definition: log.h:107
Definition: log.h:76
Definition: log.h:67
Definition: log.h:92
log_entry & operator=(const log_entry &other)
Assignment.
Definition: log.cc:179
Definition: log.h:42
Definition: log.h:23
Definition: log.h:123
Definition: log.h:105
Definition: log.h:74
Definition: log.h:104
Definition: log.h:44
const log_entry & operator[](int index) const
Return entry for a given index.
Definition: log.h:276
Definition: log.h:114
Definition: log.h:50
Definition: log.h:98
Definition: log.h:106
Definition: log.h:78
Definition: log.h:53
Definition: log.h:27
Definition: log.h:57
Definition: log.h:122
Definition: log.h:62
Definition: log.h:54
int when() const
Time since midnight of log entry.
Definition: log.h:195
Definition: log.h:86
Definition: log.h:96
Definition: log.h:97
Definition: log.h:65
Class to log actions that occur in LibPkg.
Definition: log.h:215
Definition: log.h:90
Definition: log.h:51
Definition: log.h:111
Definition: log.h:28
bool bad() const
The log failed to add one or more items.
Definition: log.h:235
Definition: log.h:103
Definition: log.h:87
std::string text() const
Description of this log entry.
Definition: log.cc:214
Definition: log.h:43
Definition: log.h:101
Definition: log.h:64
Definition: log.h:56
Definition: log.h:80
Definition: log.h:20
Definition: log.h:75
Definition: log.h:61
Definition: log.h:63
Definition: log.h:108
int code() const
Log entry error code.
Definition: log.h:174
Definition: log.h:100
unsigned int size() const
Total number of entries.
Definition: log.h:269
const_iterator end() const
Iterator to last log entry.
Definition: log.h:267
Definition: log.h:30
A class to represent one log entry.
Definition: log.h:130
LogCode
An enumeration of all the items that can be logged.
Definition: log.h:19
Definition: log.h:49
Definition: log.h:110
Definition: log.h:124

Reference Manual LibPkg Version 0.6.1 (28 Jan 2015)