Linux环境下Log4cpp-1.1.1 的下载、安装、配置

Log4cpp的主页为:http://sourceforge.net/projects/log4cpp/

       下载log4cpp-1.1.1. tar.gz    tar zxvf log4cpp-1.1.1 tar.gz  -C  /usr/local 解压到该目下
          
          安装:打开终端,在/usr/local/log4cpp/
          输入以下命令,
          ./configure
          make
          make check
          make install
          这里已经安装成功,默认的路径lib库路径是/usr/local/lib/,
          头文件的位置:/usr/local/include/log4cpp
          将/usr/local/lib下的和log4cpp相关的库都拷贝到/usr/lib,
          强调:使用log4cpp时,要加上# g++ log4test.cpp -llog4cpp -lpthread,才能顺利的编译通过
         
          Makefile中包含静态库或-llog4cpp动态库
          以管理员身份登录,将自己的库所在路径/usr/local/lib添加 到/etc/ld.so.conf文件中。但一般这个文件中的内容都是一句“include /etc/ld.so.conf.d/*.conf”,因此最好在/etc/目录下新建一个文件 , 如“xxx.conf”,然后将自己的库所在路径添加 到这个conf文件中

   修改完文件后,以root身份运行  /sbin/ldconfig -v   。这一步必不可少,别丢了。


         测试文档下:
</pre><pre name="code" class="cpp">#include <stdio.h>
#include <log4cpp/Category.hh>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/SimpleLayout.hh>

#define LOGFILE "./test.log"

int main() {
    /*Setting up Appender, layout and Category*/
    log4cpp::Appender *appender = new log4cpp::FileAppender("FileAppender",LOGFILE);//第一个参数是appender的名字,第二个是log文件的名字
    log4cpp::Layout *layout = new log4cpp::SimpleLayout();
    //log4cpp::Layout *layout = new log4cpp::BasicLayout();
    log4cpp::Category& category = log4cpp::Category::getInstance("abc");

    appender->setLayout(layout);
    category.setAppender(appender);
    category.setPriority(log4cpp::Priority::INFO);

    /*The actual logging*/
    category.info("This is for tracing the flow");
    category.notice("This is to notify certain events");
    category.warn("This is to generate certain warnings");



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

For_dongyang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值