forked from yurial/libsyslogpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
79 lines (62 loc) · 3.32 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
NAME
libsyslogpp - C++ wrapper for standard syslog interface
SYNOPSIS
#include <syslogpp.h>
Link with -lsyslogpp or with -lsyslogpp_r -pthread if you build library with multi-threading support.
libsyslogpp_r is a thread-safe library which provides a 'syslog' object for each thread. These messages with guarantee won't be mixed in proceeding sequence.
For including standard syslog mechanism define HAVE_SYSLOG_H keyword (else you should provide yours syslog functions similar to openlog, closelog, syslog, setlogmask ).
SYSLOGPP_DEFAULT_PRIO define a default messages priority, if HAVE_SYSLOG_H defined set LOG_ALERT else 0.
class syslog_t:
protected syslogbuf,
public std::ostream
{
public:
inline syslog_t(int prio = SYSLOGPP_DEFAULT_PRIO);
inline ~syslog_t();
//operator of priority modification
inline std::ostream& operator () (int prio);
//standard interface
inline void open(const char* procname, int option, int facility);
inline void close();
inline int setmask(int mask);
inline void operator () (int prio, const char* fmt, ...) const;
};
STANDARD INTERFACE
Standard interface contains overriding of the standard syslog definition and preserves the compatibility with standard interface:
openlog( "name", LOG_PID, LOG_DAEMON );
setlogmask( LOG_UPTO( LOG_DEBUG ) );
syslog( LOG_DEBUG, "%s", "test message" );
closelog();
STREAM INTERFACE
syslog class derived from std::ostream and provides a standard stream interface:
syslog.open( "name", LOG_PID, LOG_DAEMON );
syslog.setmask( LOG_UPTO( LOG_DEBUG ) );
syslog << "test message" << std::endl;
syslog.close();
Data which has been redirected to syslog remains in buffer till synchronization. Synchronization is called automatically by any standard handler for which it's typical(std::endl, std::flush) or by direct call of method flush();
You should call operator () for change of a message's priority:
syslog( LOG_DEBUG );
All messages will be send to syslog with current priority until the last one won't be changed.
You can mix changing of messages priority and data redirection:
syslog( LOG_DEBUG ) << "test message" << std::endl;
The operator of priority modification transfers data from internal buffer to syslog with the previous priority before setting a new priority value.
syslog( LOG_DEBUG ) << "message1";
syslog( LOG_NOTICE ) << "message2" << std::endl; //send "message1" with priority LOG_DEBUG and "message2" with priority LOG_NOTICE.
You can substitute standard behavior of the predetermined stream output object like for std::cout, std::cerr and std::clog:
#include <stdlib.h>
#include <iostream>
#include <syslogpp.h>
int main(int argc, char* argv[])
{
syslog.open( NULL, LOG_PID, LOG_USER );
syslog( LOG_ERR );
std::clog.rdbuf( syslog.rdbuf() );
std::clog << "test message" << std::endl;
syslog.close();
return EXIT_SUCCESS;
}
The substitution of std::cerr requires the inclusion of buffering. Use it with std::nounitbuf manipulator else std::cerr will send each message separately.
AUTHORS
Document written by:
Yuri Dyatchenko admin@yurial.ru
Roman Dolgov alter.pub@gmail.com