Linux下log4cxx的安装和配置
来源:互联网 发布:gulp.js下载 编辑:程序博客网 时间:2024/04/27 04:25
本节的主要内容是如何在Linux下进行Log4cxx的配置,基于的Linux版本是Ubuntu,不同应该同样适用于其他的Linux发型版本(推测,没有实际的测试)。下面详述安装与配置的相关过程(全部操作都是在文本模式下进行,建议是在root账户下操作)。
第一步:下载Log4cxx相关软件和文件包,分别是:apr-1.4.6.tar.gz, apr-util-1.4.1.tar.gz,apache-log4cxx-0.10.0.tar.gz三个文件,可以根据需要下载相应的版本,本节是基于上面的三个版本,在Linux下的下载方法(文本模式下):
注:假设当前目录为test,则全部下载完毕后该目录下会有apr-1.4.6.tar.gz、apr-util-1.4.1.tar.gz、apache-log4cxx-0.10.0.tar.gz三个文件
apr-1.4.6.tar.gz:wget http://apr.apache.org/apr-1.4.6.tar.gz
apr-util.1.4.1.tar.gz:wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.4.1.tar.gz(apache//apr是两个斜杠间隔的)
apache-log4cxx-0.10.0.tar.gz:
wget http://apache.etoak.com/logging/log4cxx/0.10.0/apache-log4cxx-0.10.0.tar.gz
第二步:解压下载的三个文件,在shell下敲入:
tar zxvfapr-1.4.6.tar.gz # 生成apr-1.4.6文件夹
tar.zxvfapr-util-1.4.1.tar.gz # 生成apr-util-1.4.1文件夹
tar zxvfapache-log4cxx-0.10.0.tar.gz # 生成apache-log4cxx-0.10.0文件夹
第三步:编译Log4cxx相关程序
1. apr-1.4.6
A. cd apr-1.4.6 # 进入apr-1.4.6目录
B. ./configure --prefix=/usr/local/apr
C. make
D. make install
2.apr-util-1.4.1.tar.gz
A. cd ../apr-util-1.4.1
B. ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
C. make
D.make install
3.apache-log4cxx-0.10.0
A. cd ../apache-log4cxx-0.10.0
B. ./configure --prefix=/usr/local/log4cxx--with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util
C. make
D. make install
上述执行完毕后,可以看到在/usr/local目录下生成的三个文件:apr、apr-util和log4cxx。
第四步:修改Log4cxx程序
1.vimsrc/main/cpp/inputstreamreader.cpp
增加#include <string.h>;
#include<log4cxx/logstring.h>
#include<log4cxx/helpers/inputstreamreader.h>
#include<log4cxx/helpers/exception.h>
#include<log4cxx/helpers/pool.h>
#include<log4cxx/helpers/bytebuffer.h>
+
#include<string.h>
+
否则会出现inputstreamreader.cpp:66: error: 'memmove' was not declared in thisscope
make[3]: ***[inputstreamreader.lo] 错误 1
2.vimsrc/main/cpp/socketoutputstream.cpp
增加#include <string.h>;
#include<log4cxx/logstring.h>
#include<log4cxx/helpers/socketoutputstream.h>
#include<log4cxx/helpers/socket.h>
#include<log4cxx/helpers/bytebuffer.h>
+
#include<string.h>
+
否则会出现socketoutputstream.cpp:52: error: 'memcpy' was not declared in thisscope
3.vimsrc/examples/cpp/console.cpp
增加#include <string.h>,#include <stdio.h>;
+
#include<stdio.h>
+
#include<stdlib.h>
+
#include<string.h>
+
#include<log4cxx/logger.h>
#include<log4cxx/consoleappender.h>
#include<log4cxx/simplelayout.h>
#include<log4cxx/logmanager.h>
#include<iostream>
#include<locale.h>
否则会出现
console.cpp:In function ‘int main(int, char**)’:
console.cpp:58:错误:‘puts’在此作用域中尚未声明
第五步:配置Log4cxx环境
ExportLD_LIBRARY_PATH=/usr/local/apr/bin/:/usr/local/apr-util/bin:/usr/local/log4cxx/bin/:$LD_LIBRARY_PATH
经过上面的五步,Log4cxx在Linux下的环境配置已经完毕。
下面是测试实例:
第一步:编写Log4cxx配置文件:test.properties
# Root logger
Log4j.rootLogger=DEBUG,list
# Appender:list
log4j.appender.list=org.apache.log4j.FileAppender
log4j.appender.list.File=./list.log
log4j.appender.list.ImmediateFlush=true
log4j.appender.list.Append=true
log4j.appender.list.layout=org.apache.log4j.PatternLayout
log4j.appender.list.layout.ConversionPattern=%d{yyyy-MM-ddHH:mm:SS} %5p -%m %n
第二步:编写测试程序
#include<log4cxx/logger.h>
#include<log4cxx/propertyconfigurator.h>
usingnamespace log4cxx;
int main()
{
// Read configure file
PropertyConfigurator::configure("./test.properties");
// Get root logger
LoggerPtr rootLogger = Logger:getRootLogger();
// Log information
LOG4CXX_TRACE(rootLogger, "TRACE");
LOG4CXX_DEBUG(rootLogger, "DEBUG");
LOG4CXX_WARN(rootLogger, "WARN");
LOG4CXX_INFO(rootLogger, "INFO");
LOG4CXX_ERROR(rootLogger, "ERROR");
return 0;
}
第三步:编译
g++ -o testtest.cc –L/usr/local/log4cxx/bin –llog4cxx –I/usr/local/log4cxx/include
执行完后生成test可执行文件
第四步:运行
./test
以上是Log4cxx在Linux下的测试实例。
注:其中本节涉及到的Linux相关命令可以查询相关资料了解。
- Linux下log4cxx的安装和配置
- linux下安装log4cxx
- log4cxx的linux下的安装
- Linux下log4cxx的安装使用
- Linux 下log4cxx环境配置
- Linux下编译安装log4cxx
- [转载] log4cxx在Linux下的安装、使用
- Linux下编译安装log4cxx 0.10.0
- Linux下编译安装log4cxx 0.10.0
- log4cxx在linux下的编译使用
- log4cxx在linux下的编译使用
- log4cxx在linux下的编译使用
- Linux下log4cxx的交叉编译
- Centos下安装Log4cxx
- Centos下安装Log4cxx
- Centos下安装Log4cxx
- linux下编译log4cxx
- linux 下编译log4cxx
- sgu 193 Chinese Girls' Amusement
- 关于c++输出菱形*的问题
- 利用Session完成用户的登录和注销(1)
- 常用linux网络配置命令
- CKEditor API
- Linux下log4cxx的安装和配置
- 大小端对齐
- Hadoop Failed to set permissions of path 错误处理
- 几种开源软件的读音
- 21312312312
- Tyvj P2059(传递闭包)
- Android应用开发揭秘的第4个程序3_3_MusicService修改版和高仿版的源码注释
- 数据的存储结构(即物理结构)
- 文件的读入