当前位置:网站首页>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
边栏推荐
- [Vani有约会]雨天的尾巴
- 2022 0726 Gu Yujia's study notes
- 单臂路由(讲解+实验)
- QT连接sqlite数据库的错误及其修改办法
- Federal Reserve SR 11-7: Guidance on model risk management - Wanzi collection
- 在rhel7.3中编译和使用log4cxx
- C程序代码的内存结构分析
- 如何借助自动化工具落地DevOps|含低代码与DevOps应用实践
- ?实验 7 基于 Mysql 的 PHP 管理系统实现
- ? Experiment 7 implementation of PHP management system based on MySQL
猜你喜欢

Advanced IO outline

C4D动画如何提交云渲染农场快速渲染?

Drools (5): drools advanced syntax

C# 常用功能整合-3

【WSL2】配置连接 USB 设备并使用主机的 USB 摄像头

MySQL: 提高最大连接数

Usage of string class

Esp8266 (esp-12f) third party library use -- sparkfun_ Apds9960 (gesture recognition)

A Competitive Swarm Optimizer for Large Scale Optimization

Which C4d cloud rendering platform to cooperate with?
随机推荐
查看服务器重启前的 dmesg 日志
(2022 Niuke multi school III) j-journey (Dijkstra)
A Competitive Swarm Optimizer for Large Scale Optimization
杂谈:最近好多朋友谈出国……
Confluence漏洞学习——CVE-2021-26084/85,CVE-2022-26134漏洞复现
MySQL2
35. Search insert position
Basic functions and collections of guava
Pg_relation_size 问题
Py2exe QT interface style becomes Win98 solution
Esp8266 (esp-12f) third party library use -- sparkfun_ Apds9960 (gesture recognition)
Synchronized锁
海康h9摄像头用xshell无法连接(没有启用ssh)
MySQL limit paging query optimization practice
用shell来计算文本中的数字之和
C language pthread_ cleanup_ Push() and pthread_ cleanup_ Pop() function (used for the resource cleaning task after the termination action in the critical resource program segment to avoid deadlock. T
SQLite 常用功能整合
Codeforces Round #787 (Div. 3)(7/7)
Which C4d cloud rendering platform to cooperate with?
[Vani has a date] tail on rainy days