log4cpp在unix下的使用

引用自:http://blog.csdn.net/xiaolongzhou1225/article/details/1172338
今天终于完成了对
log4cppunix下的使用,下面是一些总结
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的初步使用,以后需要验证多线程情况下的使用,以及日志的备份,大小的设定等等

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值