LogSink.h

Go to the documentation of this file.
00001 #ifndef __LOGSINK_H__
00002 #define __LOGSINK_H__
00003 
00004 namespace oasys {
00005 
00006 //----------------------------------------------------------------------------
00012 class LogSink {
00013 public:
00014     virtual ~LogSink() {}
00015     
00016     virtual void rotate()       = 0;
00017     virtual void log(char* str) = 0;
00018 };
00019 
00020 //----------------------------------------------------------------------------
00024 class ForkSink : public LogSink {
00025 public:
00026     ForkSink(LogSink* a, LogSink* b)
00027         : a_(a), b_(b) {}
00028 
00029     void rotate() { 
00030         a->rotate(); 
00031         b->rotate(); 
00032     }
00033 
00034     void log(const char* str) {
00035         a->log(str);
00036         b->log(str);
00037     }
00038 };
00039 
00040 //----------------------------------------------------------------------------
00044 class FileLogSink : public LogSink {
00045 public:
00050     FileLogSink(const char* filename);
00051     ~FileLogSink();
00052 
00053     void rotate();
00054     void log(const char* str);
00055 
00056 private:
00057     char filename_[256];
00058     int  fd_;
00059 };
00060 
00061 //----------------------------------------------------------------------------
00062 class RingBufferLogSink : public LogSink {
00063 public:
00064     RingBufferLogSink();
00065 
00066     void rotate() {}
00067     void log(char* str);
00068 
00069     static const int NUM_BUFFERS = 32;
00070     static const int BUF_LEN     = 512;
00071 
00072 private:
00073     int   cur_buf_;
00074     char* buf_;
00075     char  static_buf_[NUM_BUFFERS * BUF_LEN + 16];
00076 
00077     size_t buf(int i) {
00078         return &buf_[i * BUF_LEN];
00079     }
00080 };
00081 
00082 } // namespace oasys
00083 
00084 #endif /* __LOGSINK_H__ */

Generated on Fri Dec 22 14:47:59 2006 for DTN Reference Implementation by  doxygen 1.5.1