log4cxx安装使用
log4cxx安装使用
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=
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{}:%L - %m%n
test.properties
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/
log4cxx安装使用的更多相关文章
- log4cxx安装和使用
log4cxx是Java社区著名的log4j的c++移植版,用于为C++程序提供日志功能,以便开发者对目标程序进行调试和审计,log4cxx是apache软件基金会的开源项目,基于APR实现跨平台支持 ...
- ubuntu下log4cxx安装使用
需要安装log4cxx,安装的过程中可是充满了坎坷...最大的问题是在make log4cxx时,总是报undefined XML什么什么的错误,查了一下也没解决了,然后把apr-utils删了重新装 ...
- 在RHEL5.2 64bit下编译安装log4cxx错误
apache-log4cxx.0.10.0 依赖于apache-apr和apache-apr-utils两个包 先安装他们俩,然后编译log4cxx,发现make失败,错误如下 ronized.o . ...
- log4cxx日志库RedHat下安装
今天领导交给我一个任务:把log4cxx库在Redhat系统上面安装起来 首先.我得到信息,安装这个库一共须要三个软件 apr-1.4.6.tar.gz apr-util-1.4.1.tar.gz a ...
- 编译安装log4cxx
1.介绍 Log4cxx是开放源代码项目Apache Logging Service的子项目之一,是Java社区著名的log4j的c++移植版,用于为C++程序提供日志功能,以便开发者对目标程序进行调 ...
- (转)Linux下编译安装log4cxx
Linux下编译安装log4cxx 一个项目的服务器端在Linux平台下,用到了开源日志库log4cxx,这个库是apache项目的一个子库.功能很不错.下面记录下它的编译和安装过程. log4cxx ...
- log4cxx入门第一篇--一个小例子
先看官网:http://logging.apache.org/log4cxx/index.html 转载自:http://wenku.baidu.com/view/d88ab5a9d1f34693da ...
- log4cxx在linux下的编译使用
最近在linux下使用log4cxx库,按照其官方文档提供的方法来进行编译,不能成功,又利用google搜索了好几个中文博客上讲述在linux下编译使用log4cxx库的方法,依然不能成功,在这里我奉 ...
- log4cxx入门篇
log4cxx入门篇 先看官网:http://logging.apache.org/log4cxx/index.html 转载自:http://wenku.baidu.com/view/d88 ...
随机推荐
- stm32之时钟控制
本文提到的有以下内容: 时钟系统与总线矩阵 SysTick系统定时器 RTC实时时钟 看门狗定时器 通用定时器 一.时钟系统与总线矩阵 stm32F4的时钟树如下图所示: 在STM32中,有五个时钟源 ...
- Linux JDK1.4卸载与1.6的安装
Linux JDK卸载与安装 一.jdk1.4卸载 Redhat Enterprise 5 中自带安装了jdk1.4,在安装jdk1.6前,把jdk1.4卸载: 1.首先查看系统自带JDK的版本: [ ...
- C# 写 LeetCode easy #7 Reverse Integer
7.Reverse Integer Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 ...
- 黑科技抢先尝(续) - Windows terminal中WSL Linux 终端的极简美化指南
目录 修改默认源,为apt-get安装提速 安装python 和 python pip 安装 zsh 安装powerline-font中的特定字体 安装powerline-shell 修改~目录下的配 ...
- Linux之vim常用扩展操作
多窗口编辑 批量注释和自定义注释 显示行号 1.多窗口编辑 2.批量注释和自定义注释 3.显示行号(临时生效) 命令行模式下输入: set nu 显示行号 set nonu 不显示行号
- U3D Shader基础
http://blog.sina.com.cn/s/blog_471132920101dcnr.html 转载自风宇冲Unity3D教程学院 一个SubShader(渲染方案)是由一个个Pass块来执 ...
- 洛谷P3572 [POI2014]PTA-Little Bird
P3572 [POI2014]PTA-Little Bird 题目描述 In the Byteotian Line Forest there are nn trees in a row. On top ...
- [Xcode 实际操作]六、媒体与动画-(11)UIView视图卷曲动画的制作
目录:[Swift]Xcode实际操作 本文将演示UIView视图卷曲动画的制作. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit cla ...
- mui框架使用心得
这段时间一直在用mui框架做项目,现在很多快速开发的app大部分是用MUI和APICloud开发的.所以我就把他们对比了一下. mui有自己的UI组件,我在项目中,很少用框架的UI组件,而使用框架的j ...
- 条件分页 分页条件和页参数传递方式一 超链接拼串 方式二 使用查询表单searchForm
<%-- Created by IntelliJ IDEA. User: jie Date: 2019/5/10 Time: 20:00 To change this template use ...