当前位置:网站首页>Log4qt usage of logbase in QT project
Log4qt usage of logbase in QT project
2022-07-05 06:44:00 【Suzhou frog】
A log4qt As the log base of the project application layer , Just write down log4qt The use of .
1. Download and compile
2.log4qt The configuration file log4qt.conf
log4j.rootLogger=INFO,ROLLING_FILE
log4j.appender.ROLLING_FILE=org.apache.log4j.RollingFileAppender
log4j.appender.ROLLING_FILE.AppendFile=true
log4j.appender.ROLLING_FILE.MaxFileSize=10MB
log4j.appender.ROLLING_FILE.MaxBackupIndex=5
log4j.appender.ROLLING_FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ROLLING_FILE.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%p] %m%nLog parameter description , Reprinted from Log4Qt Basic use of _52_ Hertz's whale blog -CSDN Blog _log4qt
One . The meaning of the parameter is explained
Type of output level
ERROR、WARN、INFO、DEBUG
ERROR For a serious mistake It's mainly a program error
WARN For general warning , such as session The loss of
INFO For general information to be displayed , For example, log in and log out
DEBUG Debug information for the program
Configure log information output destination
log4j.appender.appenderName = fully.qualified.name.of.appender.class
1.org.apache.log4j.ConsoleAppender( Console )
2.org.apache.log4j.FileAppender( file )
3.org.apache.log4j.DailyRollingFileAppender( Generate a log file every day )
4.org.apache.log4j.RollingFileAppender( A new file is generated when the file size reaches the specified size )
5.org.apache.log4j.WriterAppender( Send log information in stream format to any specified place )
Configure the format of log information
log4j.appender.appenderName.layout = fully.qualified.name.of.layout.class
1.org.apache.log4j.HTMLLayout( With HTML Tabular layout ),
2.org.apache.log4j.PatternLayout( The layout mode can be specified flexibly ),
3.org.apache.log4j.SimpleLayout( Contains the level of log information and the information string ),
4.org.apache.log4j.TTCCLayout( Include the time when the log was generated 、 Threads 、 Categories and so on )
Console options
Threshold=DEBUG: Specifies the lowest level of output for log messages .
ImmediateFlush=true: The default value is true, It means that all messages will be output immediately .
Target=System.err: By default :System.out, Specify output console
FileAppender Options
Threshold=DEBUF: Specifies the lowest level of output for log messages .
ImmediateFlush=true: The default value is true, It means that all messages will be output immediately .
File=mylog.txt: Specifies that the message is output to mylog.txt file .
Append=false: The default value is true, Add the message to the specified file ,false To overlay a message over a specified file content .
RollingFileAppender Options
Threshold=DEBUG: Specifies the lowest level of output for log messages .
ImmediateFlush=true: The default value is true, It means that all messages will be output immediately .
File=mylog.txt: Specifies that the message is output to mylog.txt file .
Append=false: The default value is true, Add the message to the specified file ,false To overlay a message over a specified file content .
MaxFileSize=100KB: The suffix can be KB, MB Or is it GB. When the log file reaches that size , It will scroll automatically , Move the original content to mylog.log.1 file .
MaxBackupIndex=2: Specifies the maximum number of scrolling files that can be generated .
log4j.appender.A1.layout.ConversionPattern=%-4r %-5p %d{yyyy-MM-dd HH:mm:ssS} %c %m%n
The meaning of several symbols in log information format :
-X Number : X Information output is left aligned ;
%p: Output log information priority , namely DEBUG,INFO,WARN,ERROR,FATAL,
%d: Output the date or time of the log time point , The default format is ISO8601, You can also specify the format after , such as :%d{yyy MMM dd HH:mm:ss,SSS}, The output is similar to :2002 year 10 month 18 Japan 22:10:28,921
%r: The output starts from the application to the output log The number of milliseconds that information takes
%c: Category of output log information , Usually the full name of the class
%t: Output the name of the thread that generated the log event
%l: Where the output log event occurred , amount to %C.%M(%F:%L) The combination of , Including category name 、 The thread that happened , And the number of lines in the code . give an example :Testlog4.main (TestLog4.java:10)
%x: Outputs... Associated with the current thread NDC( Nested diagnostic environment ), Especially for things like java servlets In such a multi client and multi thread application .
%%: Output one "%" character
%F: The name of the file where the output log message was generated
%L: Line number in the output code
%m: The message specified in the output code , Specific information of the generated log
%n: Output a carriage return line feed ,Windows The platform is "\r\n",Unix The platform is "\n" Output log information line feed
Can be in % Add a modifier to the pattern character to control its minimum width 、 Maximum width 、 Alignment with text . Such as :
1) c: Specify the output category The name of , The minimum width is 20, If category The name of is less than 20 Words , Right alignment by default .
2)%-20c: Specify the output category The name of , The minimum width is 20, If category The name of is less than 20 Words ,"-" The number specifies left alignment .
3)%.30c: Specify the output category The name of , The biggest width is 30, If category The name of is greater than 30 Words , It will cut off the extra characters on the left , But less than 30 There will be no spaces .
4) .30c: If category The name of is less than 20 Just fill in the blanks , And right , If its name is longer than 30 character , Just truncate the characters that are output from the far left .
3. Project use
//path by log4qt Profile path
Log4Qt::PropertyConfigurator::configure("log4qt.conf");
// stay Release Lower all qDebug()、qFatal() Wait for the debugging information output to the console to be written to the log file ,Debug Set not to write
#ifdef QT_DEBUG
Log4Qt::LogManager::setHandleQtMessages(false);
#else
Log4Qt::LogManager::setHandleQtMessages(true);
#endif
//logger Multiple can be added Appender, So you can write the same message to multiple outputs “ file ” in , Only one... Is output here
QList<Log4Qt::Appender*> appenders = Log4Qt::Logger::rootLogger()->appenders();
for(int i=0; i<appenders.size(); i++)
{
Log4Qt::Appender* appender = appenders[i];
Log4Qt::FileAppender* fileAppender = dynamic_cast<Log4Qt::FileAppender*>(appender);
if(fileAppender)
{
QString homePath = GetHomePath();
QDir dir(homePath);
if (!dir.exists()) {
dir.mkpath(homePath);
}
fileAppender->setFile("path");
fileAppender->activateOptions();
break;
}
}边栏推荐
- 【MySQL8.0不支持表名大写-对应方案】
- Vant weave swipecell sets multiple buttons
- All English in the code
- Client use of Argo CD installation
- 3. Oracle control file management
- A brief introduction to heading/pitch/roll and omega/phi/kappa
- Adg5412fbruz-rl7 applies dual power analog switch and multiplexer IC
- LSA Type Explanation - detailed explanation of lsa-2 (type II LSA network LSA) and lsa-3 (type III LSA network Summary LSA)
- Genesis builds a new generation of credit system
- CGroup CPU group source code analysis
猜你喜欢
![[Gaode map POI stepping pit] amap Placesearch cannot be used](/img/4c/55586ffcc2267c477a4532ab51a0c1.png)
[Gaode map POI stepping pit] amap Placesearch cannot be used

1. Create Oracle database manually

安装OpenCV--conda建立虚拟环境并在jupyter中添加此环境的kernel

Knapsack problem acwing 9 Group knapsack problem

数据库Mysql全部

Game theory acwing 892 Steps Nim game

将webApp或者H5页面打包成App

Find the combination number acwing 889 01 sequence meeting conditions

MPLS experiment

What is linting
随机推荐
Positive height system
NVM Downloading npm version 6.7.0... Error
Utf8 encoding
MySQL (UDF authorization)
[algorithm post interview] interview questions of a small factory
our solution
求组合数 AcWing 888. 求组合数 IV
3.Oracle-控制文件的管理
Huawei bracelet, how to add medicine reminder?
H5内嵌App适配暗黑模式
Some classic recursion problems
[moviepy] unable to find a solution for exe
SRE核心体系了解
Game theory acwing 894 Split Nim game
Dameng database all
VLAN experiment
Vscode editor
Configuration method and configuration file of SolidWorks GB profile library
[learning] database: several cases of index failure
Stack acwing 3302 Expression evaluation
https://github.com/devbean/log4qt