Log printing in Java:
Log Tool class:
1 #获取日志 INFO: Indicates the level of the Get log A1: Represents the log register, you can customize the name2#===DEBUG INFO3Log4j.rootlogger=Debug,a1,a2,a34 5 6 7 ####################### #控制台日志 ####################################8 9 #定义日志A1存放器Ten Onelog4j.appender.a1=Org.apache.log4j.ConsoleAppender A - #输出到控制台 system.err System.out - thelog4j.appender.a1.target=System.out - - #配置日志输出格式 - +log4j.appender.a1.layout=Org.apache.log4j.PatternLayout - +LOG4J.APPENDER.A1.LAYOUT.CONVERSIONPATTERN=[%P][%T][%D{YYYY-MM-DD Hh\:mm\:ss}][%c][%l]-%m%N A at - ####################### #mysql日志输出 #################################### -log4j.logger.com.floor.shop.user.dao=DEBUG - - - ####################### #文件日志日志 #################################### in - #每天产生一个日志文件 to +Log4j.appender.a2=Org.apache.log4j.DailyRollingFileAppender - the #日志输出文件 * $Log4j.appender.A2.File = log2/TestLog.logPanax Notoginseng -#Append =false: The default value is True, the message is added to the specified file, and false means that the message is overwritten with the specified file content. the +Log4j.appender.A2.Append =true A the#Threshold =debuf: Specifies the lowest level of output for log messages. + -Log4j.appender.A2.Threshold =INFO $ $ #每天一次文件 - -Log4j.appender.a2.datepattern= '. ' yyyy-mm-DD the - #配置日志输出格式Wuyi theLog4j.appender.A2.layout =Org.apache.log4j.PatternLayout - WuLog4j.appender.A2.layout.ConversionPattern =%-d{yyyy-mm-dd HH:mm:ss} [%t]%m%N - About $ - ####################### #文件日志日志2 #################################### - -Log4j.appender.A3 =Org.apache.log4j.DailyRollingFileAppender A +Log4j.appender.A3.File = log2/Errorlog.log the -Log4j.appender.A3.Append =true $ theLog4j.appender.A3.Threshold =ERROR the theLog4j.appender.a3.datepattern= '. ' yyyy-mm-DD the -Log4j.appender.A3.layout =Org.apache.log4j.PatternLayout in theLog4j.appender.A3.layout.ConversionPattern =%-d{yyyy-mm-dd HH:mm:ss} [%t]%m%nView Code
Log4j.properties Explanation:
11. Types of output levels2 ERROR, WARN, INFO, DEBUG3 Error is a critical error, mainly a program4 WARN for general warnings, such as session loss5 Info is the general information to display, such as login log out6 Debug information for the program72. Configure log information output destination8 Configuration Format9Log4j.appender.appenderName = Fully.qualified.name.of.appender.classTen For example One1.log4j.appender.appendername =Org.apache.log4j.ConsoleAppender (console) A2.log4j.appender.appendername =org.apache.log4j.FileAppender (file) -3.log4j.appender.appendername =org.apache.log4j.DailyRollingFileAppender (Generate a log file every day) -4.log4j.appender.appendername =Org.apache.log4j.RollingFileAppender (creates a new file when the file size reaches the specified size) the5.log4j.appender.appendername =Org.apache.log4j.WriterAppender (send log information in stream format to any specified location) -3Configuring the format of log information - Configuration Format -Log4j.appender.appenderName.layout = Fully.qualified.name.of.layout.class + For example -1.log4j.appender.appendername.layout =org.apache.log4j.HTMLLayout (Layout in HTML table Form), +2.log4j.appender.appendername.layout =Org.apache.log4j.PatternLayout (flexibility to specify layout mode), A3.log4j.appender.appendername.layout =Org.apache.log4j.SimpleLayout (contains the level of log information and the information string), at4.log4j.appender.appendername.layout =Org.apache.log4j.TTCCLayout (contains information about the time, thread, category, etc.) of the log -4. Console and file Options - A. Console configuration Consoleappender -Threshold=DEBUG: Specifies the lowest level of output for log messages. -Immediateflush=true: The default value is true, meaning that all messages will be output immediately. -target=System.err: By default: System.out, specify output console in B. File Configuration Fileappender -Threshold=debuf: Specifies the lowest level of output for log messages. toImmediateflush=true: The default value is true, meaning that all messages will be output immediately. +file=mylog.txt: Specifies the message output to the Mylog.txt file. -Append=false: The default value is True, the message is added to the specified file, and false means that the message is overwritten with the specified file content. the B. File Configuration Rollingfileappender *Threshold=DEBUG: Specifies the lowest level of output for log messages. $Immediateflush=true: The default value is true, meaning that all messages will be output immediately. Panax Notoginsengfile=mylog.txt: Specifies the message output to the Mylog.txt file. -Append=false: The default value is True, the message is added to the specified file, and false means that the message is overwritten with the specified file content. theMaxfilesize=100KB: The suffix can be kb, MB, or GB. When the log file reaches this size, it will automatically scroll to move the original content to the Mylog.log.1 file. +maxbackupindex=2: Specifies the maximum number of scrolling files that can be produced. A c. Output format configuration patternlayout thelog4j.appender.a1.layout.conversionpattern=%-4r%-5p%d{yyyy-mm-dd HH:mm:ssS}%c%m%N +5The meaning that several symbols in the log Information format represent: -[%p] [%t] [%d{yyyy-mm-dd Hh\:mm\:ss}] [%c] [%l]-%m%N $[INFO] [Http-apr-8080-exec-7] [2017-08-30 16:45:34] [Com.day36.springMVC.common.aop.TestAop] [+]---------log------------- $-x: The x information output is left-aligned; -%p: Output log information priority, i.e. Debug,info,warn,error,fatal, -%d: the date or time of the output log time, the default format is ISO8601, can also be specified after the format, such as:%d{yyy MMM dd hh:mm:ss,sss}, output similar: October 18, 2002 22:10:28,921 the%R: The number of milliseconds to output the log information from the application boot to output -%C: The class that the output log information belongs to, which is usually the full name of the classWuyi%T: Output the name of the thread that generated the log event the%l: The location of the output log event, which corresponds to the combination of%c.%m (%f:%l), including the class name, the thread that occurred, and the number of rows in the code. Example: Testlog4.main (testlog4.java:10) -%x: The NDC (nested diagnostic environment) associated with the output and current line threads, especially for multi-client multithreaded applications such as Java Servlets. WuPercent: Output a "%"character -%F: The name of the file where the output log message was generated About%L: line number in the output code $%m: Output the message specified in the code, resulting in the log specific information -%n: Output a carriage return line break, Windows platform is "/r/n", UNIX platform is "/n"output log Information line wrapping -can be in%a modifier is added to the pattern character to control its minimum width, maximum width, and text alignment. - such as: A +1)%20c: Specifies the name of the output category, the minimum width is 20, if the category name is less than 20, the default is the right alignment. the -2)%-20c: Specify the name of the output category, the minimum width is 20, if the category name is less than 20, "-"The number specifies left-justified. $ the3)%. 30c: Specify the name of the output category, the maximum width is 30, if the category name is greater than 30, will be the left more than the character of the cut off, but less than 30 will not have a space. the the4)%20.30c: If the category name is less than 20, fill in the blanks, and right-aligned, if its name is longer than 30 characters, it is truncated from the far left character.
SQL statement output from MySQL:
Log printing in Java