1、熟悉log4cpp的用法,动手敲代码
http://blog.youkuaiyun.com/liuhong135541/article/category/1496383
#include<log4cpp/PatternLayout.hh>
#include<iostream>
#include<log4cpp/OstreamAppender.hh>
#include<log4cpp/RollingFileAppender.hh>
#include<log4cpp/Category.hh>
#include<log4cpp/Priority.hh>
using std::cout;
using std::endl;
using std::cin;
using namespace log4cpp;
void test(){
PatternLayout *ptlo = new PatternLayout();//日志格式
ptlo->setConversionPattern("%d %c [%p] %m %n");
RollingFileAppender *proll = new RollingFileAppender("roll123","log.txt",5*1024,3);
proll->setLayout(ptlo);
Category &root = Category::getRoot();
root.addAppender(proll);
root.setPriority(Priority::ERROR);
size_t idx = 0;
while(idx < 10){
root.emerg("emerg = 0");
root.fatal("fatal = 0");
root.alert("alter = 100");
root.crit("crit = 200");
root.error("error = 300");
root.warn("warn = 400");
root.notice("notice = 500");
root.info("info = 600");
root.debug("debug = 700");
++idx;
}
Category::shutdown();
return;
}
✹ int main(int argc,char *argv[]){
test();
return 0;
}