#include <iostream>
#include <log4cpp/Category.hh>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/RollingFileAppender.hh>
#include <log4cpp/Priority.hh>
#include <log4cpp/PatternLayout.hh>
using namespace std;
#pragma comment (lib,"log4cppD.lib")
#pragma comment (lib,"log4cpp.lib")
int main(int argc, char* argv[])
{
log4cpp::Appender* appender = new log4cpp::FileAppender("FileAppender","./test_log4cpp1.log");
log4cpp::PatternLayout* pLayout = new log4cpp::PatternLayout();
pLayout->setConversionPattern("%d: %p %c %x: %m%n");
appender->setLayout(pLayout);
log4cpp::Category& root = log4cpp::Category::getRoot();
log4cpp::Category& infoCategory = root.getInstance("infoCategory");
infoCategory.addAppender(appender);
infoCategory.setPriority(log4cpp::Priority::INFO);
infoCategory.info("system is running");
infoCategory.warn("system has a warning");
infoCategory.error("system has a error, can't find a file");
infoCategory.fatal("system has a fatal error,must be shutdown");
infoCategory.info("system shutdown,you can find some information in system log");
//回滚文件
log4cpp::PatternLayout* pRollLayout = new log4cpp::PatternLayout();
pRollLayout->setConversionPattern("%d: %p %c %x: %m%n");
log4cpp::RollingFileAppender* rollfileAppender = new log4cpp::RollingFileAppender(
"rollfileAppender","info.log",5*1024*1024,1);
rollfileAppender->setLayout(pRollLayout);
log4cpp::Category& rollCat = log4cpp::Category::getRoot().getInstance("rollCat");
rollCat.addAppender(rollfileAppender);
rollCat.setPriority(log4cpp::Priority::DEBUG);
rollCat.info("rollCat system is running");
rollCat.warn("rollCat system has a warning");
rollCat.error("rollCat system has a error, can't find a file");
rollCat.fatal("rollCat system has a fatal error,must be shutdown");
rollCat.info("rollCat system shutdown,you can find some information in system log");
log4cpp::Category::shutdown();
return 0;
}