• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ibrcommon/ibrcommon/SyslogStream.h

Go to the documentation of this file.
00001 /*
00002  * File:   SyslogStream.h
00003  * Author: morgenro
00004  *
00005  * Created on 17. November 2009, 13:43
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,      /* system is unusable */
00021                 SYSLOG_ALERT =  LOG_ALERT,      /* action must be taken immediately */
00022                 SYSLOG_CRIT =   LOG_CRIT,       /* critical conditions */
00023                 SYSLOG_ERR =    LOG_ERR,        /* error conditions */
00024                 SYSLOG_WARNING =    LOG_WARNING,        /* warning conditions */
00025                 SYSLOG_NOTICE = LOG_NOTICE,     /* normal but significant condition */
00026                 SYSLOG_INFO =   LOG_INFO,       /* informational */
00027                 SYSLOG_DEBUG =  LOG_DEBUG       /* debug-level messages */
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  /* _SYSLOGSTREAM_H */
00059 

Generated on Wed Mar 30 2011 11:11:49 for IBR-DTNSuite by  doxygen 1.7.1