00001 #ifdef __win32__
00002 #include <io.h>
00003 #else
00004
00005 #endif
00006
00007 #include "LogSink.h"
00008
00009 namespace oasys {
00010
00011
00012 FileLogSink::FileLogSink(const char* filename)
00013 : fd_(0)
00014 {
00015 strcpy(filename_, filename);
00016 }
00017
00018
00019 void
00020 FileLogSink::rotate()
00021 {
00022
00023 }
00024
00025
00026 void
00027 FileLogSink::log(const char* str)
00028 {
00029
00030
00031 #ifdef __win32__
00032 _write(fd_, str, strlen(str));
00033 #else
00034 #endif
00035 }
00036
00037
00038
00039 RingBufferLogSink::RingBufferLogSink()
00040 : cur_buf_(0)
00041 {
00042 memset(static_buf_, 0, NUM_BUFFERS * BUF_LEN + 16);
00043
00044
00045 memcpy(static_buf_, "|RNGBUF|", 8);
00046 memcpy(static_buf_ + NUM_BUFFERS * BUF_LEN + 8, "|RNGBUF|", 8);
00047
00048 buf_ = static_buf_ + 8;
00049 }
00050
00051
00052 void
00053 RingBufferLogSink::log(const char* str)
00054 {
00055 cur_buf_ = (cur_buf_ + 1) % NUM_BUFFERS;
00056 char* buf = at(cur_buf_);
00057
00058 size_t len = strlen(str);
00059 if (len > BUF_LEN - 4) {
00060 len = BUF_LEN - 4;
00061 memcpy(cur_buf_, "...", 4);
00062 } else {
00063 cur_buf_[len] = '\0';
00064 }
00065 memcpy(cur_buf_, str, len);
00066 }
00067
00068
00069
00070 }