日志滚动
日志滚动条件
1、文件大小(例如每写满1G换下一个文件)
2、时间(每天零点新建一个日志文件,不论前一个文件是否写满)
一个典型的日志文件名
logfile_test.20130411-115604.popo.7743.log
Logger 类图
File类图
file类是LogFile的一个内置类
LogFile头文件(logfile.h)
<div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: rgb(231, 229, 220); width: 936.3368530273438px; overflow: auto; padding-top: 1px; margin: 18px 0px !important;"><div class="bar" style="padding-left: 45px;"><div class="tools" style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: rgb(248, 248, 248); border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153);"><strong>[cpp]</strong> <a target=_blank href="http://blog.csdn.net/laohan_/article/details/14278287#" class="ViewSource" title="view plain" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">view plain</a><a target=_blank href="http://blog.csdn.net/laohan_/article/details/14278287#" class="CopyToClipboard" title="copy" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">copy</a><a target=_blank href="http://blog.csdn.net/laohan_/article/details/14278287#" class="PrintSource" title="print" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">print</a><a target=_blank href="http://blog.csdn.net/laohan_/article/details/14278287#" class="About" title="?" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">?</a><div style="position: absolute; left: 562px; top: 1630px; width: 32px; height: 16px; z-index: 99;"></div></div></div><ol start="1" class="dp-cpp" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important;"><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#ifndef MUDUO_BASE_LOGFILE_H</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#define MUDUO_BASE_LOGFILE_H</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include <muduo/base/Mutex.h></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include <muduo/base/Types.h></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include <boost/noncopyable.hpp></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include <boost/scoped_ptr.hpp></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">namespace</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> muduo </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{ </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">class</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> LogFile : boost::noncopyable </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{ </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">public</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">: </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> LogFile(<span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> string& basename, </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">size_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> rollSize, </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">bool</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> threadSafe = </span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">true</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">, </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> flushInterval = 3); </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> ~LogFile(); </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> append(</span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">char</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">* logline, </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> len); </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> flush(); </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">private</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">: </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> append_unlocked(</span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">char</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">* logline, </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> len); </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">static</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> string getLogFileName(</span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> string& basename, </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">time_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">* now); </span><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//获取日志文件路径</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> rollFile(); </span><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//滚动日志</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> string basename_; </span><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//日志文件basename</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">size_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> rollSize_; </span><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//日志文件达到 rolSize_ 换一个新文件</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> flushInterval_; </span><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//日志文件写入间隔时间 ,不是每一次的日志都直接写入文件,这样也有助于提高效率</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> count_; </span><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//计数器 ,当达到kCheckTimeRoll_时,会去检测是否要滚动日志文件 </span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> boost::scoped_ptr<MutexLock> mutex_; </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">time_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> startOfPeriod_; </span><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//开始记录日志时间(调整至零点)</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">time_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> lastRoll_; </span><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//上一次滚动日志文件时间</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">time_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> lastFlush_;</span><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//上一次日志写入文件时间</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">class</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> File; </span><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//日志文件类</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> boost::scoped_ptr<File> file_; <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//日子文件指针,这是一个智能指针</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">static</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> kCheckTimeRoll_ = 1024; </span><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">static</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> kRollPerSeconds_ = 60*60*24; </span><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//一天</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">}; </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">} </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#endif // MUDUO_BASE_LOGFILE_H</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li></ol></div>
LogFile的源文件
<div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: rgb(231, 229, 220); width: 936.3368530273438px; overflow: auto; padding-top: 1px; margin: 18px 0px !important;"><div class="bar" style="padding-left: 45px;"><div class="tools" style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: rgb(248, 248, 248); border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153);"><strong>[cpp]</strong> <a target=_blank href="http://blog.csdn.net/laohan_/article/details/14278287#" class="ViewSource" title="view plain" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">view plain</a><a target=_blank href="http://blog.csdn.net/laohan_/article/details/14278287#" class="CopyToClipboard" title="copy" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">copy</a><a target=_blank href="http://blog.csdn.net/laohan_/article/details/14278287#" class="PrintSource" title="print" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">print</a><a target=_blank href="http://blog.csdn.net/laohan_/article/details/14278287#" class="About" title="?" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">?</a><div style="position: absolute; left: 562px; top: 2751px; width: 32px; height: 16px; z-index: 99;"></div></div></div><ol start="1" class="dp-cpp" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important;"><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include <muduo/base/LogFile.h></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include <muduo/base/Logging.h> // strerror_tl</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include <muduo/base/ProcessInfo.h></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include <assert.h></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include <stdio.h></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include <time.h></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">using</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">namespace</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> muduo; </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">// not thread safe 不是线程安全</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">class</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> LogFile::File : boost::noncopyable </span><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//不可复制</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{ </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">public</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">:、 </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">/********</span> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;"> //File 类</span> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;"></span> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;"> **********/</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">explicit</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> File(</span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> string& filename) </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> : fp_(::fopen(filename.data(), <span class="string" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">"ae"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">)), </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> writtenBytes_(0) </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> assert(fp_); <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//断言fp_指针是否为空</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> ::setbuffer(fp_, buffer_, <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">sizeof</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> buffer_); </span><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//是指缓冲区的大小</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">// posix_fadvise POSIX_FADV_DONTNEED ?</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//虚构函数 , 关闭fp_指针</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> ~File() </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> ::fclose(fp_); </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//追加 日志</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> append(</span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">char</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">* logline, </span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">size_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> len) </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">size_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> n = write(logline, len); </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">size_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> remain = len - n; </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">while</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> (remain > 0) </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">size_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> x = write(logline + n, remain); </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">if</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> (x == 0) </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> err = ferror(fp_); </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">if</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> (err) </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> fprintf(stderr, <span class="string" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">"LogFile::File::append() failed %s\n"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">, strerror_tl(err)); </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">break</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">; </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> n += x; </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> remain = len - n; <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">// remain -= x</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> writtenBytes_ += len; </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//清空缓冲区</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> flush() </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> ::fflush(fp_); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">size_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> writtenBytes() </span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> { </span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">return</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> writtenBytes_; } </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">private</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">: </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//不加锁写入文件,logfile已经加锁了</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">size_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> write(</span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">char</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">* logline, </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">size_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> len) </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#undef fwrite_unlocked</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">return</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> ::fwrite_unlocked(logline, 1, len, fp_); </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">FILE</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">* fp_; </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">char</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> buffer_[64*1024]; </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">size_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> writtenBytes_; </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">}; </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">/*******</span> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;"></span> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">LogFile类</span> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">*******/</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">LogFile::LogFile(<span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> string& basename, </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">size_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> rollSize, </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">bool</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> threadSafe, </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> flushInterval) </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> : basename_(basename),<span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//文件basename</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> rollSize_(rollSize),<span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//日志滚动大小界限</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> flushInterval_(flushInterval), <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//清空缓冲区</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> count_(0), </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> mutex_(threadSafe ? <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">new</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> MutexLock : NULL),</span><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//是否以线程安全的方式进行操作</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> startOfPeriod_(0), </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> lastRoll_(0), </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> lastFlush_(0) </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{ </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//断言 ,basename 是否包含"/"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> assert(basename.find(<span class="string" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">'/'</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">) == string::npos); </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//滚动日志</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> rollFile(); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">} </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">LogFile::~LogFile() </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{ </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">} </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//追加 日志记录</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> LogFile::append(</span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">char</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">* logline, </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> len) </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{ </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">if</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> (mutex_) </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> MutexLockGuard lock(*mutex_); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> append_unlocked(logline, len); </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">else</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> append_unlocked(logline, len); </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">} </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> LogFile::flush() </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{ </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">if</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> (mutex_) </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> MutexLockGuard lock(*mutex_); </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> file_->flush(); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">else</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> file_->flush(); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">} </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> LogFile::append_unlocked(</span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">char</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">* logline, </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> len) </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{ </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> file_->append(logline, len); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//判断是否要滚动日志文件了 ,大小上测试</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">if</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> (file_->writtenBytes() > rollSize_) </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//滚动日志文件</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> rollFile(); </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">else</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//时间上测试 ,就是计数器</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">if</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> (count_ > kCheckTimeRoll_) </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> count_ = 0; </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">time_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> now = ::time(NULL); </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">time_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> thisPeriod_ = now / kRollPerSeconds_ * kRollPerSeconds_; </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">if</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> (thisPeriod_ != startOfPeriod_) </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> rollFile(); </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//是否应该清空数据</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">else</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">if</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> (now - lastFlush_ > flushInterval_) </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> lastFlush_ = now; </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> file_->flush(); </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//计数器++</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">else</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> ++count_; </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">} </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//日志滚动</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> LogFile::rollFile() </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{ </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">time_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> now = 0; </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> string filename = getLogFileName(basename_, &now); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">time_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> start = now / kRollPerSeconds_ * kRollPerSeconds_; </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//如果是时间上的滚动,那么就要更新一下时间了</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">if</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> (now > lastRoll_) </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> lastRoll_ = now; </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> lastFlush_ = now; </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> startOfPeriod_ = start; </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> file_.reset(<span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">new</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> File(filename)); </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">} </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//得到日志文件名</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">string LogFile::getLogFileName(<span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> string& basename, </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">time_t</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">* now) </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{ </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> string filename; </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> filename.reserve(basename.size() + 64); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> filename = basename; </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">char</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> timebuf[32]; </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">char</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> pidbuf[32]; </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">struct</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">tm</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">tm</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">; </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> *now = time(NULL); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> gmtime_r(now, &<span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">tm</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">); </span><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">// FIXME: localtime_r ?</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> strftime(timebuf, <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">sizeof</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> timebuf, </span><span class="string" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">".%Y%m%d-%H%M%S."</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">, &</span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">tm</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">); </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> filename += timebuf; </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> filename += ProcessInfo::hostname(); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> snprintf(pidbuf, <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">sizeof</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> pidbuf, </span><span class="string" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">".%d"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">, ProcessInfo::pid()); </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> filename += pidbuf; </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> filename += <span class="string" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">".log"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">; </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">return</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> filename; </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">} </span></li></ol></div>
LogFile测试类 LogFile_Test.cc
<div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: rgb(231, 229, 220); width: 936.3368530273438px; overflow: auto; padding-top: 1px; margin: 18px 0px !important;"><div class="bar" style="padding-left: 45px;"><div class="tools" style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: rgb(248, 248, 248); border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153);"><strong>[cpp]</strong> <a target=_blank href="http://blog.csdn.net/laohan_/article/details/14278287#" class="ViewSource" title="view plain" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">view plain</a><a target=_blank href="http://blog.csdn.net/laohan_/article/details/14278287#" class="CopyToClipboard" title="copy" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">copy</a><a target=_blank href="http://blog.csdn.net/laohan_/article/details/14278287#" class="PrintSource" title="print" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">print</a><a target=_blank href="http://blog.csdn.net/laohan_/article/details/14278287#" class="About" title="?" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">?</a><div style="position: absolute; left: 562px; top: 6992px; width: 32px; height: 16px; z-index: 99;"></div></div></div><ol start="1" class="dp-cpp" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important;"><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include <muduo/base/LogFile.h></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include <muduo/base/Logging.h></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">boost::scoped_ptr<muduo::LogFile> g_logFile; </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//msg日志内容,日志长度</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> outputFunc(</span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">const</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">char</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">* msg, </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> len) </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{ </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> g_logFile->append(msg, len); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">} </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> flushFunc() </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{ </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> g_logFile->flush(); </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">} </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> main(</span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> argc, </span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">char</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">* argv[]) </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{ </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">char</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> name[256]; </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> strncpy(name, argv[0], 256); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//日志滚动的大小200*1000 = 196k</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> g_logFile.reset(<span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">new</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> muduo::LogFile(::basename(name), 200*1000)); </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//Logger的输出函数</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> muduo::Logger::setOutput(outputFunc); </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//Logger的缓冲区清空函数</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> muduo::Logger::setFlush(flushFunc); </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//日志</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> muduo::string line = <span class="string" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">"1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ "</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">; </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//10000条日志记录</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">for</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> (</span><span class="datatypes" style="margin: 0px; padding: 0px; border: none; color: rgb(46, 139, 87); background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> i = 0; i < 10000; ++i) </span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> { </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> LOG_INFO << line << i; </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> usleep(1000); </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">} </span></li></ol></div>
程序输出:
<div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: rgb(231, 229, 220); width: 936.3368530273438px; overflow: auto; padding-top: 1px; margin: 18px 0px !important;"><div class="bar" style="padding-left: 45px;"><div class="tools" style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: rgb(248, 248, 248); border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153);"><strong>[cpp]</strong> <a target=_blank href="http://blog.csdn.net/laohan_/article/details/14278287#" class="ViewSource" title="view plain" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">view plain</a><a target=_blank href="http://blog.csdn.net/laohan_/article/details/14278287#" class="CopyToClipboard" title="copy" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">copy</a><a target=_blank href="http://blog.csdn.net/laohan_/article/details/14278287#" class="PrintSource" title="print" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">print</a><a target=_blank href="http://blog.csdn.net/laohan_/article/details/14278287#" class="About" title="?" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">?</a><div style="position: absolute; left: 562px; top: 7883px; width: 32px; height: 16px; z-index: 99;"></div></div></div><ol start="1" class="dp-cpp" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important;"><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">[root@localhost bin]# ls -lh logfile_test* </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">-rwxr-xr-x. 1 root root 610K Oct 17 16:02 logfile_test </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">-rw-r--r--. 1 root root 196K Oct 17 16:03 logfile_test.20131017-080304.localhost.localdomain.2656.log </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">-rw-r--r--. 1 root root 196K Oct 17 16:03 logfile_test.20131017-080309.localhost.localdomain.2656.log </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">-rw-r--r--. 1 root root 196K Oct 17 16:03 logfile_test.20131017-080312.localhost.localdomain.2656.log </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">-rw-r--r--. 1 root root 196K Oct 17 16:03 logfile_test.20131017-080314.localhost.localdomain.2656.log </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">-rw-r--r--. 1 root root 196K Oct 17 16:03 logfile_test.20131017-080316.localhost.localdomain.2656.log </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">-rw-r--r--. 1 root root 196K Oct 17 16:03 logfile_test.20131017-080319.localhost.localdomain.2656.log </span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 20px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">-rw-r--r--. 1 root root 87K Oct 17 16:03 logfile_test.20131017-080321.localhost.localdomain.2656.log </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 20px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">[root@localhost bin]# </span></li></ol></div>