首先从 https://github.com/apache/log4cxx/tree/mcatan 下载源代码,目前最新的版本是0.10.0
git clone https://github.com/apache/log4cxx.git
这时直接./configure 会报错,找不到apr和apr-uitl, 所以还需要先安装这2个包
wget http://mirrors.hust.edu.cn/apache//apr/apr-1.5.2.tar.gz
wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.4.tar.gz
先编译安装apr
tar xzvf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure
make
make install
tar xzvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure
make
make install
cd log4cxx
./configure
make
make instal
如果不能打印中文日志可以重新 configure编译,如下
./configure --with-charset=utf-8 --with-logchar=utf-8
make
make install
在编译的时候我报了一个错,如下
In file included from ../../../src/main/include/log4cxx/spi/filter.h:24:0,
from ../../../src/main/include/log4cxx/filter/andfilter.h:27,
from andfilter.cpp:18:
../../../src/main/include/log4cxx/spi/loggingevent.h:171:45: error: declaration of 'typedef log4cxx::spi::KeySet log4cxx::spi::LoggingEvent::KeySet' [-fpermissive]
typedef spi::KeySet KeySet;
^
In file included from ../../../src/main/include/log4cxx/helpers/objectptr.h:21:0,
from ../../../src/main/include/log4cxx/spi/filter.h:21,
from ../../../src/main/include/log4cxx/filter/andfilter.h:27,
from andfilter.cpp:18:
../../../src/main/include/log4cxx/spi/loggingevent.h:46:34: error: changes meaning of 'KeySet' from 'typedef class std::vector<std::basic_string<char> > log4cxx::spi::KeySet' [-fpermissive]
LOG4CXX_LIST_DEF(KeySet, LogString);
typedef spi::KeySet KeySet;
KeySet getMDCKeySet() const;