PTLib
Version 2.10.10
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
syslog.h
Go to the documentation of this file.
1
/*
2
* syslog.h
3
*
4
* System Logging class.
5
*
6
* Portable Tools Library
7
*
8
* Copyright (c) 2009 Equivalence Pty. Ltd.
9
*
10
* The contents of this file are subject to the Mozilla Public License
11
* Version 1.0 (the "License"); you may not use this file except in
12
* compliance with the License. You may obtain a copy of the License at
13
* http://www.mozilla.org/MPL/
14
*
15
* Software distributed under the License is distributed on an "AS IS"
16
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17
* the License for the specific language governing rights and limitations
18
* under the License.
19
*
20
* The Original Code is Portable Windows Library.
21
*
22
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23
*
24
* Contributor(s): ______________________________________.
25
*
26
* $Revision: 24994 $
27
* $Author: rjongbloed $
28
* $Date: 2011-01-04 17:13:51 -0600 (Tue, 04 Jan 2011) $
29
*/
30
31
#ifndef _PSYSTEMLOG
32
#define _PSYSTEMLOG
33
34
#ifdef P_USE_PRAGMA
35
#pragma interface
36
#endif
37
38
#include "
ptlib/udpsock.h
"
39
40
class
PSystemLogTarget
;
41
42
47
class
PSystemLog
:
public
PObject
,
public
iostream
48
{
49
PCLASSINFO(
PSystemLog
,
PObject
);
50
public
:
53
54
enum
Level
{
56
StdError
= -1,
58
Fatal
,
60
Error
,
62
Warning
,
64
Info
,
66
Debug
,
68
Debug2
,
70
Debug3
,
72
Debug4
,
74
Debug5
,
76
Debug6
,
77
78
NumLogLevels
79
};
80
82
PSystemLog
(
83
Level
level
84
);
85
87
~PSystemLog
() { flush(); }
89
94
static
PSystemLogTarget
&
GetTarget
();
95
98
static
void
SetTarget
(
99
PSystemLogTarget
* target,
100
bool
autoDelete =
true
101
);
103
104
private
:
105
PSystemLog
(
const
PSystemLog
& other);
106
PSystemLog
& operator=(
const
PSystemLog
&);
107
108
class
Buffer
:
public
streambuf {
109
public
:
110
Buffer
();
111
virtual
int_type overflow(int_type=EOF);
112
virtual
int_type underflow();
113
virtual
int
sync();
114
PSystemLog
* m_log;
115
PString
m_string;
116
} m_buffer;
117
friend
class
Buffer
;
118
119
Level
m_logLevel;
120
121
friend
class
PSystemLogTarget
;
122
};
123
124
125
class
PSystemLogTarget
:
public
PObject
126
{
127
PCLASSINFO(
PSystemLogTarget
,
PObject
);
128
public
:
131
PSystemLogTarget
();
133
139
void
SetThresholdLevel
(
140
PSystemLog::Level
level
141
) {
m_thresholdLevel
= level; }
142
148
PSystemLog::Level
GetThresholdLevel
()
const
{
return
m_thresholdLevel
; }
150
151
protected
:
156
virtual
void
Output
(
157
PSystemLog::Level
level,
158
const
char
* msg
159
) = 0;
160
163
void
OutputToStream
(
164
ostream & strm,
165
PSystemLog::Level
level,
166
const
char
* msg
167
);
169
170
protected
:
171
PSystemLog::Level
m_thresholdLevel
;
172
173
private
:
174
PSystemLogTarget
(
const
PSystemLogTarget
& other);
175
PSystemLogTarget
& operator=(
const
PSystemLogTarget
&);
176
177
friend
class
PSystemLog::Buffer
;
178
};
179
180
183
class
PSystemLogToNowhere
:
public
PSystemLogTarget
184
{
185
PCLASSINFO(
PSystemLogToNowhere
,
PSystemLogTarget
);
186
public
:
187
virtual
void
Output
(
PSystemLog::Level
,
const
char
*)
188
{
189
}
190
};
191
192
195
class
PSystemLogToStderr
:
public
PSystemLogTarget
196
{
197
PCLASSINFO(
PSystemLogToStderr
,
PSystemLogTarget
);
198
public
:
203
virtual
void
Output
(
204
PSystemLog::Level
level,
205
const
char
* msg
206
);
208
};
209
210
213
class
PSystemLogToFile
:
public
PSystemLogTarget
214
{
215
PCLASSINFO(
PSystemLogToFile
,
PSystemLogTarget
);
216
public
:
219
PSystemLogToFile
(
220
const
PString
& filename
221
);
223
228
virtual
void
Output
(
229
PSystemLog::Level
level,
230
const
char
* msg
231
);
233
238
const
PFilePath
&
GetFilePath
()
const
{
return
m_file
.
GetFilePath
(); }
240
241
protected
:
242
PTextFile
m_file
;
243
};
244
245
248
class
PSystemLogToNetwork
:
public
PSystemLogTarget
249
{
250
PCLASSINFO(
PSystemLogToNetwork
,
PSystemLogTarget
);
251
public
:
252
enum
{
RFC3164_Port
= 514 };
253
256
PSystemLogToNetwork
(
257
const
PIPSocket::Address
& address,
258
WORD port =
RFC3164_Port
,
259
unsigned
facility = 16
260
);
261
PSystemLogToNetwork
(
262
const
PString
& hostname,
263
WORD port =
RFC3164_Port
,
264
unsigned
facility = 16
265
);
267
272
virtual
void
Output
(
273
PSystemLog::Level
level,
274
const
char
* msg
275
);
277
278
protected
:
279
PIPSocket::Address
m_host
;
280
WORD
m_port
;
281
unsigned
m_facility
;
282
PUDPSocket
m_socket
;
283
};
284
285
286
#ifdef WIN32
287
289
class
PSystemLogToDebug :
public
PSystemLogTarget
290
{
291
PCLASSINFO
(PSystemLogToDebug,
PSystemLogTarget
);
292
public
:
297
virtual
void
Output
(
298
PSystemLog::Level
level,
299
const
char
* msg
300
);
302
};
303
#elif !defined(P_VXWORKS)
304
306
class
PSystemLogToSyslog
:
public
PSystemLogTarget
307
{
308
PCLASSINFO(
PSystemLogToSyslog
,
PSystemLogTarget
);
309
public
:
312
PSystemLogToSyslog
();
313
~PSystemLogToSyslog
();
315
320
virtual
void
Output
(
321
PSystemLog::Level
level,
322
const
char
* msg
323
);
325
};
326
#endif
327
328
333
#define PSYSTEMLOG(level, variables) \
334
if (PSystemLog::GetTarget().GetThresholdLevel() >= PSystemLog::level) { \
335
PSystemLog P_systemlog(PSystemLog::level); \
336
P_systemlog << variables; \
337
} else (void)0
338
339
340
#endif
341
342
343
// End Of File ///////////////////////////////////////////////////////////////
include
ptlib
syslog.h
Generated on Tue May 7 2013 20:34:15 for PTLib by
1.8.1.2