log4cpp简单示例

下载地址

Sample.cpp

复制代码
#include <iostream>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/Category.hh>
#pragma comment(lib, "log4cpp/log4cppD.lib")
int main()
{
    log4cpp::FileAppender *fileAppender = new log4cpp::FileAppender("DEFAULT", "StubProgram.log");
    log4cpp::PatternLayout *patternLayout = new log4cpp::PatternLayout;
    patternLayout->setConversionPattern("%d{%Y/%m/%d-%H:%M:%S}\t%p\t%m%n");
    fileAppender->setLayout(patternLayout);
    log4cpp::Category &category = log4cpp::Category::getRoot();
    category.addAppender(fileAppender);
    category.info("I'm %u years old! --- 我%u岁!", 24, 24);
    category.warn("Warned %s", "one time");
    category.error("No error, %s", "all is well!");
    std::cout << "Sample Finished" << std::endl;
    std::system("pause");
    return 0;
}
复制代码

 https://www.cnblogs.com/buyishi/p/9155090.html

posted @ 2019-01-29 04:22  findumars  Views(740)  Comments(0Edit  收藏  举报