进程信息 获取/proc/seft文件夹各文件中数据参数及系统参数
文件
ReadSmallFile类
读取文件数据到缓冲区 < 64KB
AppendFile类
设置缓冲区为64KB,写采用fwrite_unlocked,并非线程安全
GzipFile类
.gz的文件处理
LogFile类
const string basename_;
const off_t rollSize_; //滚动文件大小
const int flushInterval_; //刷新时间默认3秒
const int checkEveryN_; //检查刷新或重置文件次数 默认1024次
int count_; //写入次数 每checkEveryN_次重置
boost::scoped_ptr<MutexLock> mutex_;
time_t startOfPeriod_;
time_t lastRoll_;
time_t lastFlush_;
boost::scoped_ptr<FileUtil::AppendFile> file_;
const static int kRollPerSeconds_ = 60*60*24; //一天
默认是线程安全的写文件(利用mutex_)
日志
对moduo日志库的讲解,目前发现已有人写的很不错:
muduo 日志库学习(一)
muduo 日志库学习(二)
日志调用顺序:
Logger.Impl.LogStream.detail::FixedBuffer
Logger析构函数会输出到指定文件,默认是stdout
Logger::~Logger()
{
impl_.finish();
const LogStream::Buffer& buf(stream().buffer());
g_output(buf.data(), buf.length());
if (impl_.level_ == FATAL)
{
g_flush();
abort();
}
}
异步日志
由AsyncLogging类实现。重新设置日志的输出函数调用AsyncLogging.append(),日志就会先缓存在:
AsyncLogging.FixedBuffer<muduo::detail::kLargeBuffer>
算是二级缓存区吧。
AsyncLogging.start()会启动线程并在线程入口函数threadFunc中:
LogFile output(basename_, rollSize_, false);
日志最终输出到output中,由于只需要启动一个日志线程,所以不需要加锁写。
至此,base部分全部结束。