Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef IBRCOMMON_SYSLOGSTREAM_H
00009 #define IBRCOMMON_SYSLOGSTREAM_H
00010
00011 #include <vector>
00012 #include <syslog.h>
00013 #include <iostream>
00014 #include <string.h>
00015
00016 namespace ibrcommon
00017 {
00018 enum SyslogPriority
00019 {
00020 SYSLOG_EMERG = LOG_EMERG,
00021 SYSLOG_ALERT = LOG_ALERT,
00022 SYSLOG_CRIT = LOG_CRIT,
00023 SYSLOG_ERR = LOG_ERR,
00024 SYSLOG_WARNING = LOG_WARNING,
00025 SYSLOG_NOTICE = LOG_NOTICE,
00026 SYSLOG_INFO = LOG_INFO,
00027 SYSLOG_DEBUG = LOG_DEBUG
00028 };
00029
00030 std::ostream &operator<<(std::ostream &stream, const SyslogPriority &prio);
00031
00032 class SyslogStream : public std::streambuf
00033 {
00034 private:
00035 enum { BUF_SIZE = 256 };
00036
00037 public:
00038 SyslogStream();
00039 virtual ~SyslogStream();
00040
00041 static std::ostream& getStream();
00042 static void open(char *name, int option, int facility);
00043
00044 void setPriority(const SyslogPriority &prio);
00045
00046 protected:
00047 virtual int sync();
00048
00049 private:
00050 void writeToDevice();
00051 std::vector< char_type > m_buf;
00052 SyslogPriority _prio;
00053 };
00054
00055 extern std::ostream &slog;
00056 }
00057
00058 #endif
00059