VICI  0.11.815
Visual Chart Interpreter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
log.h
Go to the documentation of this file.
1 /*
2  * log.h
3  *
4  * Copyright 2009 - 2016 Brenton Ross
5  *
6  * This file is part of VICI.
7  *
8  * VICI is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * VICI is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with VICI. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
28 #ifndef CFI_LOG_H
29 #define CFI_LOG_H
30 
31 #include <map>
32 #include <fstream>
33 #include "vx.h"
34 #include "udpsocket.h"
35 #include "ipc.h"
36 
38 namespace VICI
39 {
40 
41 namespace cfi
42 {
43 
45 
58 class logstream : public std::ostream
59 {
60 private:
61  std::streambuf *buffer; // owned
62 
63 protected:
65  // static logstream *me;
66 
68  // static std::map< std::string, logstream * > *namedStreams;
69 
71 
74  logstream( std::streambuf *buf );
75 public:
77  virtual ~logstream();
78 
80 
83  static logstream & instance();
84 
86 
90  static logstream & instance( csr name );
91 
93 
96  void severity( Severity sev);
97 };
98 
99 
100 // --------------------------------------------------------------
101 
103 
108 class logger
109 {
110 protected:
112  logger() : sem4('L') {}
113 public:
115  virtual ~logger() {}
116 
118 
123  virtual int log( Severity sev, csr line ) = 0;
124 
126 
132  virtual int log( csr logName, Severity sev, csr line ) = 0;
133 };
134 
135 // --------------------------------------------------------------
136 
138 
144 class FormattingLogger : public logger
145 {
146 protected:
148 
151  std::string timeStamp();
152 
154  csr hostname();
155 
157  csr process();
158 
160  csr severity( Severity );
161 
163 
169  int format( std::ostream & s, Severity sev, csr msg );
170 };
171 
172 // --------------------------------------------------------------
173 
175 
177 
179 {
180 public:
182  enum Stream { COUT, CERR, CLOG };
183 
184 
185 public:
187 
190  explicit StdLogger( Stream cc ) : c(cc) {}
191 
192  // Implementations of the logger interface
193  int log( Severity, csr line );
194  int log( csr logName, Severity, csr line );
195 
196 private:
197  Stream c;
198 };
199 
200 // --------------------------------------------------------------
201 
203 
211 {
212 protected:
214  std::ofstream f;
215 
216 public:
218 
221  FileLogger( const Path &fname );
222 
223  // Implementation of the logger interface
224  int log( Severity, csr line );
225  int log( csr logName, Severity, csr line );
226 };
227 
228 // --------------------------------------------------------------
234 class PlainFileLogger : public logger
235 {
236 protected:
238  std::ofstream f;
239 
240 public:
242 
245  PlainFileLogger( const Path &fname );
246 
247  // Implementation of the logger interface
248  int log( Severity, csr line );
249  int log( csr logName, Severity, csr line );
250 };
251 
252 // --------------------------------------------------------------
254 
256 
258 {
259 protected:
262 public:
267  UDPLogger( csr hostname, int port );
268 
269  // Implementation of the logger interface
270  int log( Severity, csr line );
271  int log( csr logName, Severity, csr line );
272 };
273 
274 // --------------------------------------------------------------
276 
278 
279 class TraceLogger : public logger
280 {
281 protected:
283  std::ofstream f;
284 
285 public:
289  TraceLogger(const Path & fname );
290 
291  // Implementation of the logger interface
292  int log( Severity, csr line );
293  int log( csr logName, Severity, csr line );
294 };
295 
296 // --------------------------------------------------------------
298 
300 
301 class SystemLogger : public logger
302 {
303 public:
307  SystemLogger( csr ident );
308 
309  // Implementation of the logger interface
310  int log( Severity, csr line );
311  int log( csr logName, Severity, csr line );
312 };
313 
314 } // namespace cfi
315 } // namespace VICI
316 
317 #endif /* LOG_H_ */
int log(Severity, csr line)
log to the unnamed log
Definition: log.cpp:299
virtual ~logger()
Destructor.
Definition: log.h:115
Severity
Severity levels for log messages.
Definition: vx.h:48
virtual int log(Severity sev, csr line)=0
log to the unnamed log
Declarations for a wrapper for the UDP socket.
static logstream & instance()
Get an instance of the unnamed stream.
Definition: log.cpp:548
void severity(Severity sev)
Set the severity for the current message.
Definition: log.cpp:584
UDPLogger(csr hostname, int port)
Definition: log.cpp:258
Stream
Enumeration of the standard streams.
Definition: log.h:182
Semaphore sem4
Mutual exclusion lock.
Definition: log.h:111
int log(Severity, csr line)
log to the unnamed log
Definition: log.cpp:234
std::ofstream f
The logging stream.
Definition: log.h:283
std::string timeStamp()
generates a string containing the current time
Definition: log.cpp:83
logger that interfaces to the Linux syslog
Definition: log.h:301
std::ofstream f
The logging stream.
Definition: log.h:214
StdLogger(Stream cc)
Constructor.
Definition: log.h:190
UDPClientSocket socket
the udp socket connected to the logging server
Definition: log.h:261
logger()
Constructor.
Definition: log.h:112
int format(std::ostream &s, Severity sev, csr msg)
output the message to the stream
Definition: log.cpp:139
PlainFileLogger(const Path &fname)
Constructor.
Definition: log.cpp:220
Class for producing a formatted log message.
Definition: log.h:144
csr hostname()
generates a string containing the hostname.
Definition: log.cpp:96
SystemLogger(csr ident)
Definition: log.cpp:321
virtual ~logstream()
destructor
Definition: log.cpp:538
int log(Severity, csr line)
log to the unnamed log
Definition: log.cpp:263
Manipulate path strings.
Definition: stringy.h:74
csr severity(Severity)
generates a string containing the severity level
Definition: log.cpp:130
TraceLogger(const Path &fname)
Definition: log.cpp:286
logstream(std::streambuf *buf)
Static pointer to only instance of the anonymous object.
Definition: log.cpp:532
A UDP client socket.
Definition: udpsocket.h:110
Class for logging to a file.
Definition: log.h:210
int log(Severity, csr line)
log to the unnamed log
Definition: log.cpp:200
csr process()
generates a string containing the process id
Definition: log.cpp:114
Class for logging to a logging server.
Definition: log.h:257
An exception object with stream semantics.
Class for logging to the std output streams.
Definition: log.h:178
FileLogger(const Path &fname)
Constructor.
Definition: log.cpp:186
std::ofstream f
The logging stream.
Definition: log.h:238
int log(Severity, csr line)
log to the unnamed log
Definition: log.cpp:156
A semaphore for managing exclusive access to resources across multiple processes. ...
Definition: ipc.h:63
const std::string & csr
short cut for string constants
Definition: vici.h:80
int log(Severity, csr line)
log to the unnamed log
Definition: log.cpp:329
Declarations for the semaphore component of libcfi.
Class for logging tracing output.
Definition: log.h:279
An abstract base class used by the log stream to write logs.
Definition: log.h:108
Definition: log.h:234
A stream class specialized for logging.
Definition: log.h:58