引用自:http://blog.csdn.net/xiaolongzhou1225/article/details/1172338
今天终于完成了对log4cpp在unix下的使用,下面是一些总结
今天终于完成了对log4cpp在unix下的使用,下面是一些总结
1.将log4cpp-0.3.5rc3拷贝到unix下
2.进入log4cpp-0.3.5rc3目录,运行命令configure
3.使用make命令进行编译,会看到一些错误
首先是出错位置priority.hh
class LOG4CPP_EXPORT Priority {
public:
static const int MESSAGE_SIZE=8;
/ Some other declarations //
};
解决方法
将代码改成
static const int MESSAGE_SIZE;
在priority.cpp 里加一句
#include "PortabilityImpl.hh"
#include <log4cpp/Priority.hh>
#include <cstdlib>
const int log4cpp::Priority::MESSAGE_SIZE=8;
然后是"../include/log4cpp/FixedContextCategory.hh", line 171: Warning: log4cpp::FixedContextCategory::addA
ppender hides the virtual function log4cpp::Category::addAppender(log4cpp::Appender*).
"../include/log4cpp/FixedContextCategory.hh", line 171: Warning: log4cpp::FixedContextCategory::owns
Appender hides the virtual function log4cpp::Category::ownsAppender(log4cpp::Appender*, __rwstd::__r
b_tree<log4cpp::Appender*, std::pair<log4cpp::Appender*const, bool>, __rwstd::__select1st<std::pair<
log4cpp::Appender*const, bool>, log4cpp::Appender*>, std::less<log4cpp::Appender*>, std::allocator<s
td::pair<log4cpp::Appender*const, bool>>>::iterator&).
"FixedContextCategory.cpp", line 47: Error: Could not find a match for log4cpp::FixedContextCategory
::addAppender(log4cpp::Appender*).
需要修改FixedContextCategory.hh:
virtual void addAppender(Appender* appender) throw();
为 virtual void addAppender(Appender* appender) const throw();
FixedContextCategory.cpp:
virtual void addAppender(Appender* appender) throw();
为 virtual void addAppender(Appender* appender) const throw();
再次进行编译,就可以通过了,会在src目录生成liblog4cpp.la文件
4.测试
进入tests目录,使用make进行编译,会报"testbench.cpp", line 66: Error: The operation "log4cpp::CategoryStream << std::basic_string<char, s
td::char_traits<char>, std::allocator<char>>" is illegal.
"testbench.cpp", line 85: Error: The operation "log4cpp::CategoryStream << std::basic_string<char, s
td::char_traits<char>, std::allocator<char>>" is illegal.
将85行修改为: s<< log4cpp::CategoryStream::ENDLINE;
将66行修改为: log << log4cpp::Priority::ERROR;//log << str;
运行testmain cpp.log,在当前目录下会生成cpp.log的日志文件。
这只是log4cpp的初步使用,以后需要验证多线程情况下的使用,以及日志的备份,大小的设定等等