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} %p %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; }