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