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 ...
随机推荐
- 演讲:对 2000 多亿条数据做一次 group by 需要多久?
http://2017.qconbeijing.com/presentation/646?utm_source=weibo&utm_medium=infoq&utm_campaign= ...
- 0005_Linux下的SSH连接操作
1.启动SSH服务:service sshd start 2.开机自动启动SSH:chkconfig sshd on 3.获取Linux的ip地址:ifconfig 4.连接Linux的SSH:打开x ...
- Crypto Challenge Set 1解题报告
1.Convert hex to base64 题意:给出一个hex编码过的字符串,将它进行base64加密 解题关键:直接利用base64库函数实现 import base64 str1=" ...
- iView之DatePicker的datetimerange校验
使用DatePicker的type是datetimerange时,处理开始--结束的持续时间校验如下.遇到的问题:时间弹出校验提示,但是程序还是会继续往下走,所以调完校验后,再做判断开始时间是否为tr ...
- win32常用代码整理
1.ShellExecute [Use ShellAPI] ShellExecute(Handle, 'open', 'http://www.cnblogs.com/lovelp/', nil, ni ...
- 远程抓取win7 的用户登录时间
protected void Page_Load(object sender, EventArgs e) { InvokeSystemPS("query user /server:192.1 ...
- POJ - 1458 Common Subsequence DP最长公共子序列(LCS)
Common Subsequence A subsequence of a given sequence is the given sequence with some elements (possi ...
- CABasicAnimation动画及其keypath值和作用
//tarnsform放大缩小动画 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transf ...
- C#中Obsolete特性
一般在逼格比较高的程序员代码中常见此特性手法,他们因为某些原因不详注释掉原有的代码,用Obsolete [csharp] view plain copy class Program { static ...
- hihoweek 137(简单完全背包)
题目链接:http://hihocoder.com/contest/hiho137/problem/1 题意:中文题诶- 思路:各层的成本计算不会有影响,所以我们只要把没一层的成本计算出来在求和就是答 ...