当前位置:网站首页>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;
}
}边栏推荐
- RecyclerView的应用
- 求组合数 AcWing 888. 求组合数 IV
- Application of recyclerview
- Vscode editor
- 3.Oracle-控制文件的管理
- Speedtree01 generator properties
- Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
- Gaussian elimination acwing 884 Gauss elimination for solving XOR linear equations
- Genesis builds a new generation of credit system
- Day 2 document
猜你喜欢

cgroup_ memcg

International Open Source firmware Foundation (osff) organization

求组合数 AcWing 889. 满足条件的01序列

达梦数据库全部

Use ffmpeg to rotate, flip up and down, and flip horizontally

Financial risk control practice -- feature derivation based on time series

All English in the code

SRE核心体系了解

Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022

A brief introduction to heading/pitch/roll and omega/phi/kappa
随机推荐
4.Oracle-重做日志文件管理
20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
MPLS experiment
【高德地图POI踩坑】AMap.PlaceSearch无法使用
4. Oracle redo log file management
Vant Weapp SwipeCell設置多個按鈕
UIO driven framework
NVM Downloading npm version 6.7.0... Error
博弈论 AcWing 892. 台阶-Nim游戏
confidential! Netease employee data analysis internal training course, white whoring! (attach a data package worth 399 yuan)
MQClientException: No route info of this topic: type_ topic
Architecture
Markdown syntax
All English in the code
[algorithm post interview] interview questions of a small factory
Vant weapp swippecell set multiple buttons
Huawei bracelet, how to add medicine reminder?
Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne
Vant Weapp SwipeCell设置多个按钮
Some classic recursion problems
https://github.com/devbean/log4qt