log4cxx日誌庫RedHat下安裝

2021-09-07 10:57:15 字數 3059 閱讀 6682

今天領導交給我乙個任務:把log4cxx庫在redhat系統上面安裝起來

首先。我得到資訊,安裝這個庫一共須要三個軟體

apr-1.4.6.tar.gz

apr-util-1.4.1.tar.gz

apache-log4cxx-0.10.0.tar.gz

安裝順序是從上到下的,為什麼,由於後者的安裝依賴前者。

1.安裝log4cxx庫到哪個資料夾?

2.安裝好之後怎麼用?

我首先想到的是網上查資料,結果非常多結果都顯示:

1.針對問題1,99%的都安裝在/usr/local資料夾下(我的許可權是普通使用者。安裝在/usr/local資料夾下須要root許可權,我頓時打了個寒戰。萬一我安裝錯了,server暴了怎麼辦)

2.針對問題2,由於99%的都是安裝在/usr/local資料夾下。結果就是隨便提供乙個測試程式。直接來g++ test.cpp 其它簡單引數

我想了又想,終於依照第一步做了(在此之前我向領導要了管理員許可權),安裝好後。沒什麼問題,只是。接下來,在進行敲**測試的時候,關於log4cxx庫的檔案都找不到。我崩潰了。這和網上說的不一樣啊。

遇到了一些挫折。終於我是搞出來了,就來詳細說說我的步驟吧。

1.把三個壓縮包放置到乙個你喜歡的資料夾下。比方/home/mac/log4cxx這個資料夾下

2.在/home/mac/log4cxx資料夾下解壓三個壓縮包得到三個資料夾(解壓縮命令tar zxvf 你的目標)

3.在/home/mac/log4cxx資料夾下新建三個資料夾apr apr-util log4cxx作為三個包的安裝資料夾(執行make install時的安裝資料夾)

4.首先進入apr-1.4.6資料夾執行./configure --prefix=/home/mac/log4cxx/apr配置apr包的安裝資料夾為/home/mac/log4cxx/apr

5.執行make

6.執行make install

7.進入apr-util-1.4.1資料夾執行./configure --prefix=/home/mac/log4cxx/apr-util --with-apr=/home/mac/log4cxx/apr意義和上面一步一樣,只是多了個依賴關係

8.執行make

9.執行make install

10.進入apache-log4cxx-0.10.0資料夾執行./configure --prefix=/home/mac/log4cxx/log4cxx --with-apr=/home/mac/log4cxx/apr --with-apr-util=/home/mac/log4cxx/apr-util意義和上面一步一樣,依賴關係又體現了

11.執行make

12.執行make install

13.此時使用命令ls 瀏覽新建的三個目錄apr apr-util log4cxx,會發現裡面有一些include啊。lib啊之類的目錄

14.由於測試程式要用到log4cxx的庫檔案,所以還須要一步。執行vi /home/mac/.bashrc 在裡面加入兩句

ld_library_path=/home/mac/log4cxx/log4cxx/lib

export ld_library_path 然後儲存

15.執行source /home/mac/.bashrc使剛剛做的變動生效

16.編寫乙個測試程式main.cpp

#include #include #include int main(int argc, char* ar**) 

17.編寫檔案conf.log這個log4cxx配置檔案

log4j.rootlogger=trace, stdout, logfile
18.執行g++ -i/home/mac/log4cxx/log4cxx/include -l/home/mac/log4cxx/log4cxx/lib -llog4cxx main.cpp 

19.會生成a.out檔案

20.執行./a.out 終端輸出

2014-07-21 23:14:06,735 [0xb7fe4700] trace traceyourmama - trace

2014-07-21 23:14:06,736 [0xb7fe4700] warn traceyourmama - warn

2014-07-21 23:14:06,736 [0xb7fe4700] debug traceyourmama - debug

2014-07-21 23:14:06,736 [0xb7fe4700] error traceyourmama - assert

2014-07-21 23:14:06,736 [0xb7fe4700] fatal traceyourmama - fatal

2014-07-21 23:14:06,736 [0xb7fe4700] trace patch - trace

2014-07-21 23:14:06,736 [0xb7fe4700] error patch - error

同一時候,當前資料夾下也會有字尾名為log的檔案產生

再來從頭回答那兩個問題

1.隨你安裝在哪個資料夾,是要gcc的時候指定好正確路徑即可了

2.還是gcc的 -i -l -i的引數運用值得深究

好了。到眼下為止,最終讓這個庫起作用了。下一步就是分析怎樣配置這個庫。

後記:1.為了支援中文。即能夠輸出中文到控制台或者檔案,要在安裝log4cxx時加上 --with-charset=utf-8 --with-logchar=utf-8,比如:

./configure --prefix=/home/mac/log4cxx/log4cxx --with-apr=/home/mac/log4cxx/apr --with-apr-util=/home/mac/log4cxx/apr-util--with-charset=utf-8 --with-logchar=utf-8

2.為了輸出qt的qstring型別的字串,要這樣用,log4cxx_info(logger,qstring.tostdstring()),用log4cxx_info(logger,qstring.tostdstring().c_str())會出問題

log4cxx日誌系統

本文主要從log4cxx級別 layout 格式化 命名規則 filter幾個方面介紹。一 log4cxx命名規則 logger由乙個string類的名字識別,logger的名字是大小寫敏感的,且名字之間具有繼承的關係,子名有父名作為字首,用點號.分隔。如 x.y是x.y.z的父親。根logger ...

C 日誌系統log4cxx

直接使用yum安裝log4cxx.x86 64 庫檔案 log4cxx devel.x86 64 標頭檔案 yum install log4cxx.x86 64 庫檔案 yum install log4cxx devel.x86 64 標頭檔案 編譯安裝apr tar zxvf apr 1.5.2....

log4cxx日誌庫RedHat下安裝

今天領導交給我乙個任務 把log4cxx庫在redhat系統上面安裝起來 首先,我得到資訊,安裝這個庫一共需要三個軟體 apr 1.4.6.tar.gz apr util 1.4.1.tar.gz apache log4cxx 0.10.0.tar.gz 安裝順序是從上到下的,為什麼,因為後者的安裝...