当前位置:网站首页>Compiling and using log4cxx in rhel7.3
Compiling and using log4cxx in rhel7.3
2022-07-27 07:26:00 【hawanglc】
The logging system of an application of a company uses log4cxx, I didn't use one before , Now explore how to use . Because the host environment of different people is different , therefore , I also have various other problems in the process of pattern , Now I will summarize my problems . For future reference .
Download a software
Three are needed , Namely apr、apr-util and log4cxx. The following is the download path .
https://apr.apache.org/download.cgi
https://logging.apache.org/log4cxx/latest_stable/download.html
compile apr-1.7.0.tar.gz
decompression apr-1.7.0.tar.gz
Get into apr-1.7.0 Catalog
./configure --prefix=$HOME
--prefix Install the target library file to the specified directory
This is me docker The container of , Note the following error
rm: cannot remove 'libtoolT': No such file or directory
First install some tools that are not in the original system
yum install autoconf automake libtool
Then run the above again configure, Some images have no error prompt , Some and . If there is , take configure In the document RM='$RM' It is amended as follows RM='$RM -f ', This is equivalent to , If the deletion fails , Just ignore him . Then input
make && make install
The program can also be compiled successfully , It will be in $HOME/lib Put the compiled library file in libapr-1.so etc.
compile apr-util-1.6.1.tar.gz
decompression apr-util-1.6.1.tar.gz
Get into apr-util-1.6.1.tar Catalog
./configure --prefix=$HOME -with-apr=$HOME
make
here , The program will report an error , The message is as follows :
apr_xml.c:35:19: fatal error: expat.h: No such file or directory
It shows that the operating system lacks another tool , Install it :
yum install expat-devel
make install
It will be in $HOME/lib Put the compiled library file in libaprutil-1.so etc.
compile apache-log4cxx-0.11.0.tar.gz
decompression apache-log4cxx-0.11.0.tar.gz
Get into apache-log4cxx-0.11.0.tar
./configure --with-charset=utf-8 --with-apr=${HOME} --with-apr-util=${HOME}
There will be the following mistakes
missing aclocal-1.16 -I ………… aclocal-1.16: command not found
You can enter autoreconf -ivf To solve
make && make install
Then you can see our compiled file , There are two . This is not put in $HOME/lib The reason is the above configure Not added in --prefix Path assignment for
sh-4.2# find / -name "*liblog4cxx*" -exec ls -l {} \;
-rw-r--r-- 1 root root 38329992 Apr 9 13:54 /usr/local/lib/liblog4cxx.a
-rw-r--r-- 1 root root 1039 Apr 9 13:54 /usr/local/lib/pkgconfig/liblog4cxx.pc
lrwxrwxrwx 1 root root 20 Apr 9 13:54 /usr/local/lib/liblog4cxx.so -> liblog4cxx.so.11.0.0
lrwxrwxrwx 1 root root 20 Apr 9 13:54 /usr/local/lib/liblog4cxx.so.11 -> liblog4cxx.so.11.0.0
-rwxr-xr-x 1 root root 14307728 Apr 9 13:54 /usr/local/lib/liblog4cxx.so.11.0.0
-rwxr-xr-x 1 root root 1039 Apr 9 13:54 /usr/local/lib/liblog4cxx.la
-rw-r--r-- 1 root root 1039 Apr 9 13:45 /root/download/apache-log4cxx-0.11.0/liblog4cxx.pc
-rw-r--r-- 1 root root 1029 Aug 6 2020 /root/download/apache-log4cxx-0.11.0/liblog4cxx.pc.in
-rw-r--r-- 1 root root 38329992 Apr 9 13:54 /root/download/apache-log4cxx-0.11.0/src/main/cpp/.libs/liblog4cxx.a
lrwxr-xr-x 1 root root 16 Apr 9 13:54 /root/download/apache-log4cxx-0.11.0/src/main/cpp/.libs/liblog4cxx.la -> ../liblog4cxx.la
-rw-r--r-- 1 root root 1039 Apr 9 13:54 /root/download/apache-log4cxx-0.11.0/src/main/cpp/.libs/liblog4cxx.lai
lrwxr-xr-x 1 root root 20 Apr 9 13:53 /root/download/apache-log4cxx-0.11.0/src/main/cpp/.libs/liblog4cxx.so -> liblog4cxx.so.11.0.0
lrwxr-xr-x 1 root root 20 Apr 9 13:53 /root/download/apache-log4cxx-0.11.0/src/main/cpp/.libs/liblog4cxx.so.11 -> liblog4cxx.so.11.0.0
-rwxr-xr-x 1 root root 14307728 Apr 9 13:53 /root/download/apache-log4cxx-0.11.0/src/main/cpp/.libs/liblog4cxx.so.11.0.0
-rw-r--r-- 1 root root 1038 Apr 9 13:54 /root/download/apache-log4cxx-0.11.0/src/main/cpp/liblog4cxx.la
Write a code to test
Before use , according to c++ Development practices , The first apache-log4cxx-0.11.0/src/main Inside include Make a copy of the catalogue separately , Put it in the root directory of my project . If you don't want to copy, you can , You need to specify it yourself when compiling include The path of . The difference between these two methods is when writing code #include Instructions , You need to use double quotation marks or angle brackets .
This code refers to other netizens .
#include "log4cxx/logger.h"
#include "log4cxx/logstring.h"
#include "log4cxx/propertyconfigurator.h"
using namespace log4cxx;
int main(int argc, char *argv[])
{
// Read configuration file
PropertyConfigurator::configure("log4cxx.properties");
// Set up two logger
LoggerPtr logger1 = Logger::getLogger(argv[0]);
LOG4CXX_TRACE(logger1, " track ");
LOG4CXX_WARN(logger1, " Warning ");
LOG4CXX_DEBUG(logger1, " debugging ");
LOG4CXX_ASSERT(logger1, false, " Assertion ");
LOG4CXX_FATAL(logger1, " deadly ");
return 0;
}Write a log file , File name is log4cxx.properties
# Set up rootlogger by DEBUG Level , Used ca and fa Two Appender
log4j.rootLogger=DEBUG,ca, fa
# Yes Appender fa Set it up :
# This is a file type Appender,
# Its output file (File) by ./output.log,
# Output mode (Append) For coverage mode ,
# Output format (layout) by PatternLayout
log4j.appender.fa=org.apache.log4j.FileAppender
log4j.appender.fa.File=./output.log
log4j.appender.fa.Append=true
log4j.appender.fa.layout=org.apache.log4j.PatternLayout
log4j.appender.fa.layout.ConversionPattern=%d [%t] %-5p %c %l - %m%n
# Yes Appender ca Set it up :
# This is a console type Appender
# Output format (layout) by PatternLayout
log4j.appender.ca=org.apache.log4j.ConsoleAppender
log4j.appender.ca.layout=org.apache.log4j.PatternLayout
log4j.appender.ca.layout.ConversionPattern=%d [%t] %-5p %c %l - %m%n
In my docker Medium rhel7.3 in , The following command cannot be connected .
sh-4.2# g++ log4cxx_main.cpp -o log4cxx_main -Wall -O3 -g3 -L /usr/local/lib/ -llog4cxx
/root/lib/libaprutil-1.so.0: undefined reference to `XML_ErrorString'
/root/lib/libaprutil-1.so.0: undefined reference to `XML_SetUserData'
/root/lib/libaprutil-1.so.0: undefined reference to `XML_ParserFree'
/root/lib/libaprutil-1.so.0: undefined reference to `XML_SetElementHandler'
/root/lib/libaprutil-1.so.0: undefined reference to `XML_SetCharacterDataHandler'
/root/lib/libaprutil-1.so.0: undefined reference to `XML_GetErrorCode'
/root/lib/libaprutil-1.so.0: undefined reference to `XML_SetEntityDeclHandler'
/root/lib/libaprutil-1.so.0: undefined reference to `XML_StopParser'
/root/lib/libaprutil-1.so.0: undefined reference to `XML_ParserCreate'
/root/lib/libaprutil-1.so.0: undefined reference to `XML_Parse'
We reference various other libraries , It lacks references to other libraries . actually ,libexpat It's not what I designate alone /root/lib Medium , He is yum install expat-devel After installation, put it into /lib64 Under the . Can pass ldconfig -p | grep expat Use this command to find . The following is the complete compilation command , Regardless of apr What does it actually use :
g++ log4cxx_main.cpp -o log4cxx_main -Wall -O3 -g3 -L /usr/local/lib/ -llog4cxx -L/root/lib -lapr-1 -laprutil-1 -lexpat
Modify the runtime
Because I put apr and apr-uitl Put it on the one you specify /root/lib in , hold log4cxx Put it in the default /usr/local/lib/, So add these two paths to the runtime environment , Or directly modify the environment variable file .
LD_LIBRARY_PATH=/usr/local/lib/:/root/lib:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH
Run the program
sh-4.2# ./log4cxx_main
2021-04-10 00:03:36,315 [0x7f1e42de4740] WARN ./log4cxx_main log4cxx_main.cpp(16) - Warning
2021-04-10 00:03:36,318 [0x7f1e42de4740] DEBUG ./log4cxx_main log4cxx_main.cpp(17) - debugging
2021-04-10 00:03:36,321 [0x7f1e42de4740] ERROR ./log4cxx_main log4cxx_main.cpp(18) - Assertion
2021-04-10 00:03:36,323 [0x7f1e42de4740] FATAL ./log4cxx_main log4cxx_main.cpp(19) - deadly
here , There is a output.log Log file , First run , The content is the same as above . The files in my directory are :
sh-4.2# ls -lrt
total 156
drwxr-xr-x 7 1000 1000 224 Apr 9 13:45 include
-rw-r--r-- 1 root root 541 Apr 9 23:24 log4cxx_main.cpp
-rwxr-xr-x 1 root root 145152 Apr 9 23:24 log4cxx_main
-rw-r--r-- 1 root root 826 Apr 9 23:32 log4cxx.properties
-rw-r--r-- 1 root root 368 Apr 10 00:04 output.log
边栏推荐
猜你喜欢

Firefox browser, when accessing Tencent cloud server, failed to establish a secure connection.

No.0 training platform course-2. SSRF Foundation

How to implement Devops with automation tools | including low code and Devops application practice

Quartus: an error is reported when adding a.V file to someone else's project

Jmeter: interface automation test - BeanShell compares database data and return data

Relevant principles of MySQL index optimization

Advanced IO outline

(2022杭电多校三)1009.Package Delivery(贪心)

2022 0726 顾宇佳 学习笔记

Drools (5): drools basic syntax (3)
随机推荐
Flutter实战-请求封装(一)
杂谈:最近好多朋友谈出国……
Codeworks round 809 (Div. 2) (6/6) (Kruskal reconstruction tree)
Convert Excel to csv/csv UTF-8
Jmeter:接口自动化测试-BeanShell对数据库数据和返回数据比较
The possibility of metauniverse from the perspective of technical principles: how Omniverse "built" Mars
(2022牛客多校三)J-Journey(dijkstra)
Linear table -- stack and queue
MySQL index failure and solution practice
MySQL: 提高最大连接数
UUID与secrets模块
UI gesture actions of uiautomator common classes
Li Mu hands-on learning, in-depth learning, V2 transformer and code implementation
Bash: 创建返回布尔类型值的函数
一个优先级顺序的SQL问题
杂谈:高考
Zabbix: 将收集到值映射为易读的语句
端口转发小结
VLAN trunk experiment
ShowDoc漏洞学习——CNVD-2020-26585(任意文件上传)