当前位置:网站首页>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;
}
}边栏推荐
- Suppose a bank's ATM machine, which allows users to deposit and withdraw money. Now there is 200 yuan in an account, and both user a and user B have the right to deposit and withdraw money from this a
- VLAN experiment
- Rehabilitation type force deduction brush question notes D2
- Database mysql all
- Edge calculation data sorting
- how to understand the “model independent.“
- Bash exercise 17 writing scripts to install the server side of FRP reverse proxy software
- 5. Oracle tablespace
- Huawei bracelet, how to add medicine reminder?
- P2575 master fight
猜你喜欢

The “mode“ argument must be integer. Received an instance of Object

7. Oracle table structure

MPLS experiment

【高德地图POI踩坑】AMap.PlaceSearch无法使用

SRE核心体系了解

MySQL (UDF authorization)

4.Oracle-重做日志文件管理

Vscode creates its own code template

Suppose a bank's ATM machine, which allows users to deposit and withdraw money. Now there is 200 yuan in an account, and both user a and user B have the right to deposit and withdraw money from this a

Pycahrm reports an error: indentation error: unindent does not match any outer indentation
随机推荐
RecyclerView的应用
All English in the code
Suppose a bank's ATM machine, which allows users to deposit and withdraw money. Now there is 200 yuan in an account, and both user a and user B have the right to deposit and withdraw money from this a
2048项目实现
FFmpeg build下载(包含old version)
7. Oracle table structure
Winter messenger 2
Preemption of CFS scheduling
ADG5412FBRUZ-RL7应用 双电源模拟开关和多路复用器IC
Instruction execution time
区间问题 AcWing 906. 区间分组
how to understand the “model independent.“
[algorithm post interview] interview questions of a small factory
【MySQL8.0不支持表名大写-对应方案】
The route of wechat applet jumps again without triggering onload
Speedtree01 generator properties
Modnet matting model reproduction
What is linting
Vant Weapp SwipeCell设置多个按钮
1. Create Oracle database manually
https://github.com/devbean/log4qt