ubuntu下log4cxx安装使用
需要安装log4cxx,安装的过程中可是充满了坎坷。。。最大的问题是在make log4cxx时,总是报undefined XML什么什么的错误,查了一下也没解决了,然后把apr-utils删了重新装了一下就好了。。
log4cxx现在是apache的一个项目,用来记录日志。看名字就知道,是给c++使用的。
环境(在以下2个环境中进行验证测试):
gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16)
log4cxx依赖于apache 的 apr 和 apr-util,所以安装顺序是: apr, apr-util, log4cxx。
1.软件包下载
apr: http://apr.apache.org/download.cgi
apr-util: http://apr.apache.org/download.cgi
log4cxx: http://logging.apache.org/log4cxx/download.html
2.安装apr
#tar xzvf apr-1.5.2.tar.bz2
#cd apr-1.5.2
#./configure --prefix=/usr/local/apr
#make
#make install
3.安装apr-util
#tar xzvf apr-util-1.5.4.tar.bz2
#cd apr-util-1.5.4
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#make
#make install
4.安装log4cxx
#tar xzf apache-log4cxx-0.10.0.tar.gz
#cd apache-log4cxx-0.10.0
log4cxx直接make会报类似error: ‘memmove’ was not declared in this scope的错误,参考前人的工作,修改以下源文件:
src/main/cpp/inputstreamreader.cpp 添加 #include <string.h>
src/main/cpp/socketoutputstream.cpp 添加 #include <string.h>
src/examples/cpp/console.cpp 添加 #include <string.h> #include <stdio.h>
#./configure --prefix=/usr/local/log4cxx --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
#make
#make install
5.把编译后的库加载到环境变量中(实际使用和发布使用log4cx库需要其他更多的工作)
export LD_LIBRARY_PATH=/usr/local/apr/lib/:/usr/local/apr-util/lib/:/usr/local/log4cxx/lib/
6.测试代码
test.cpp
#include <iostream>
#include <log4cxx/logger.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/helpers/exception.h> using namespace std;
using namespace log4cxx;
using namespace log4cxx::helpers; static const string CONF_LOG_FILE = "/home/fg/src/work/test/test.properties"; LoggerPtr logger(Logger::getRootLogger()); int main(void)
{
try {
PropertyConfigurator::configure(CONF_LOG_FILE);
LOG4CXX_INFO(logger, "Init() success.");
cout << "success" << endl;
} catch (Exception &) {
cout << "log4cxx init error" << endl;
}
return ;
} test.cpp
test.properties文件的内容:
log4j.rootLogger=INFO, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=log.dat
log4j.appender.file.MaxFileSize=20MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
test.properties

log4j.rootLogger=INFO, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=log.dat
log4j.appender.file.MaxFileSize=20MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

7.编译:
g++ -o test0 test.cpp -L/usr/local/log4cxx/lib -llog4cxx -I/usr/local/log4cxx/include
运行:
./test
可以看到生成了log.dat文件,里面写入了LOG4CXX_INFO()输出的日志内容。
参考资料:
1.http://blog.chinaunix.net/uid-24512513-id-3195404.html
2.http://zipperary.com/2015/08/04/log4cxx/
ubuntu下log4cxx安装使用的更多相关文章
- Torch7在Ubuntu下的安装与配置
Torch7的本系列教程的主要目的是介绍Torch的入门使用.今天首先分享一下Torch7的安装.(在Ubuntu14.04安装torch7) 为什么选择Torch Torch的目标是在建立科学算法的 ...
- ubuntu下git安装及使用
ubuntu下git安装及使用 其实,好几个月前,就已经安装好了,可是一直搁置在那儿,所以密码等一些其它细节都忘的差不多了,所以今天就重新部署了一下,并开始积极使用......... 1,git ...
- premake Ubuntu下的安装
premake是个跨平台的编译工具,先看看在Ubuntu下怎么安装. 首先下载,在/usr目录下: sudo wget -O premake-4.4-beta4-linux.tar.gz http:/ ...
- linux,windows,ubuntu下git安装与使用
ubuntu下git安装与使用:首先应该检查本地是否已经安装了git ,如果没有安装的话,在命令模式下输入 sudo apt-get install git 进行安装 输入git命令查看安装状态及常用 ...
- ubuntu下如何安装codeblocks集成开发环境
codeblocks是一个十分优秀的C/C++开发IDE,虽然后起之秀codelite目前来看大有超越之势哦. 不过在ubuntu下安装codeblocks却比较麻烦,不像其他linux发行版,比如s ...
- ubuntu下makeinfo安装,其实真正安装的是texinfo包
操作系统环境:ubuntu 在终端中执行命令:sudo apt-get install texinfo 今天在打包的时候有个包需要 makeinfo,当时就各种搜结果就没有 makeinfo 这个 ...
- Ubuntu下软件安装方式、PATH配置、查找安装位置
Ubuntu 18.04, 安装方式 目前孤知道的Ubuntu下安装软件方式有3种(命令): 1.make 2.apt/apt-get 3.dpkg 方式1基于软件源码安装,需要经历配置(可选).编译 ...
- ubuntu 下python安装及hello world
//@desn:ubuntu 下python安装及hello world //@desn:码字不宜,转载请注明出处 //@author:张慧源 <turing_zhy@163.com> ...
- ubuntu下mysql安装(server、client、dev),开启、停止和重启,及常见错误
转自:ubuntu下mysql安装(server.client.dev),开启.停止和重启,及常见错误 1. 在ubuntu下安装server和client很简单: (1)安装server apt-g ...
随机推荐
- 【Gstreamer开发】用 GStreamer 简化 Linux 多媒体开发
原文:http://www.ibm.com/developerworks/cn/linux/l-gstreamer/ 一.基本概念 GStreamer 作为 GNOME 桌面环境推荐的流媒体应用框架, ...
- 【DSP开发】DSP能用VS2010生成的链接库文件吗?
[DSP开发]DSP能用VS2010生成的链接库文件吗? 声明:引用请注明出处http://blog.csdn.net/lg1259156776/ 说明:可能这个问题让行家看上去就会莞尔一笑,但是很多 ...
- matlab.坑01
1.数据的行列 位置 1.1.c++中二维数组与二维mwarray数据格式之间的相互转换 - weixin_38723958的博客 - CSDN博客.html(https://blog.csdn.ne ...
- spring中的BeanDefinitionRegistryPostProcessor
spring中的BeanDefinitionRegistryPostProcessor是BeanFactoryPostProcessor的子接口,BeanFactoryPostProcessor的作用 ...
- Netty源码剖析-构建链接
参考文献:极客时间傅健老师的<Netty源码剖析与实战>Talk is cheap.show me the code! ----主线: 和启动一样也是有两个线程完成的,boss threa ...
- Python re 模块findall() 函数返回值展现方式详解
findall 函数: 在字符串中找到正则表达式所匹配的所有子串,并返回一个列表,如果没有找到匹配的,则返回空列表. 注意: match 和 search 是匹配一次 findall 匹配所有,mat ...
- Thinking In Java 4th Chap3 操作符
若String后接一‘+’运算符,其后元素自动转化为String类型 注意:若对对象赋值另一对象,操作对应的是引用,如c=d,则c和d都指向原来d指向的对象 生成随机数:Random rand=new ...
- python-day3(正式学习)
执行python的两种方式 交互式 优点:运行一句执行一句,方便修改 缺点:关闭即消失,无法保存 命令行式 优点:能一直保存 缺点:代码全部写完才可以调试bug 以后尽量使用pycharm和jupyt ...
- Go-函数高级使用-条件分支-包管理-for循环-switch语句-数组及切片-与或非逻辑符
目录 科普 python 注释 # 函数高级 if else if else 包管理 下载第三方包 比较热门的框架 for 循环 for 循环的几种写法 switch 语句 数组及数组切片 数组迭代 ...
- 基于APM实现RPC服务和消息队列的指定消费
本文内容是基于公司现有框架整理的一篇专利文章.该框架包含完整的一套DevOps流程,包括工单系统(容器申请.服务部署等)\配置中心\路由配置中心\服务治理平台\消息治理平台\葛朗台(基于Docker+ ...