################################################################################ #①Configure the root Logger, its syntax is: # #log4j.rootLogger = [level],appenderName,appenderName2,... #level is the priority of logging, divided into OFF, TRACE, DEBUG, INFO, WARN, ERROR, FATAL, ALL ##Log4j recommends using only four levels, the priority from low to high is DEBUG, INFO, WARN, ERROR #By the level defined here, you can control the switch to the corresponding level of log information in the application #For example, if the INFO level is defined here, all the log information of the DEBUG level in the application will not be printed out #appenderName is to specify where the log information is output. Multiple output destinations can be specified at the same time ################################################################################ ################################################################################ #2 Configure the log information output destination Appender, its syntax is: # #log4j.appender.appenderName = fully.qualified.name.of.appender.class # log4j.appender.appenderName.optionN = valueN # The appenders provided by #Log4j are as follows: #1) org.apache.log4j.ConsoleAppender (output to console) #2) org.apache.log4j.FileAppender (output to file) #3) org.apache.log4j.DailyRollingFileAppender (generates 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 to any specified place in stream format) # #1) ConsoleAppender option property # -Threshold = DEBUG: Specify the lowest level of output of log messages # -ImmediateFlush = TRUE: The default value is true, all messages will be output immediately # -Target = System.err: Default value System.out, output to console (err is red, out is black) # #2) FileAppender option property # -Threshold = INFO: Specifies the lowest level of output of log messages # -ImmediateFlush = TRUE: The default value is true, all messages will be output immediately # -File = C:\log4j.log: Specify message output to C:\log4j.log file # -Append = FALSE: The default value is true, append the message to the specified file, false means to overwrite the content of the specified file with the message # -Encoding = UTF-8: You can specify the file encoding format # #3) DailyRollingFileAppender option property # -Threshold = WARN: Specifies the lowest level of output for log messages # -ImmediateFlush = TRUE: The default value is true, all messages will be output immediately # -File = C:\log4j.log: Specify message output to C:\log4j.log file # -Append = FALSE: The default value is true, append the message to the specified file, false means to overwrite the content of the specified file with the message # -DatePattern='.'yyyy-ww: Scroll the file once a week, that is, generate a new file every week. You can also use the following parameters: # '.'yyyy-MM:monthly # '.'yyyy-ww: weekly # '.'yyyy-MM-dd: every day # '.'yyyy-MM-dd-a: twice a day # '.'yyyy-MM-dd-HH: every hour # '.'yyyy-MM-dd-HH-mm: every minute # -Encoding = UTF-8: You can specify the file encoding format # #4) RollingFileAppender option property # -Threshold = ERROR: Specifies the lowest level of output for log messages # -ImmediateFlush = TRUE: The default value is true, all messages will be output immediately # -File = C:/log4j.log: Specify the message output to the C:/log4j.log file # -Append = FALSE: The default value is true, append the message to the specified file, false means to overwrite the content of the specified file with the message # -MaxFileSize = 100KB: The suffix can be KB, MB, GB. When the log file reaches this size, it will be automatically rolled. For example: log4j.log.1 # -MaxBackupIndex = 2: Specify the maximum number of rolling files that can be generated # -Encoding = UTF-8: You can specify the file encoding format ################################################################################ ################################################################################ #③Configure the format (layout) of the log information, its syntax is: # #log4j.appender.appenderName.layout = fully.qualified.name.of.layout.class # log4j.appender.appenderName.layout.optionN = valueN # The layouts provided by #Log4j are as follows: #5) org.apache.log4j.HTMLLayout (layout in HTML form) #6) org.apache.log4j.PatternLayout (the layout pattern can be specified flexibly) #7) org.apache.log4j.SimpleLayout (contains the level and information string of log information) #8) org.apache.log4j.TTCCLayout (including log generation time, thread, category, etc.) #9) org.apache.log4j.xml.XMLLayout (layout in XML) # #5) HTMLLayout Options Properties # -LocationInfo = TRUE: default value false, output java file name and line number # -Title=Struts Log Message: Default Log4J Log Messages # #6) PatternLayout Options Properties # -ConversionPattern = %m%n: Format the specified message (parameter meaning below) # #9) XMLLayout Options Properties # -LocationInfo = TRUE: default value false, output java file name and line number # #Log4J uses a print format similar to the printf function in C language to format log information. The print parameters are as follows: # %m print the message specified in the code # %p output priority, ie DEBUG,INFO,WARN,ERROR,FATAL # %r Output the number of milliseconds it took to output the log information since the application was started # %c The category to which the output belongs, usually the full name of the category # %t output the name of the thread that generated the log event # %n output a carriage return line feed, "\r\n" for Windows platform, "\n" for Unix platform # %d The date or time of the output log time point, the default format is ISO8601, and the format can also be specified after # Such as: %d{yyyy year MM month dd day HH:mm:ss,SSS}, the output is similar: 2012-01-05 22:10:28,921 # %l Output the location of the log event, including the category name, the thread where it occurred, and the number of lines in the code # Testlog.main(TestLog.java:10) # %F The name of the file where the output log message was generated # %L line number in output code # %x output the NDC (Nested Diagnostic Environment) associated with the current thread, in multi-client multi-threaded applications like java servlets # %% output a "%" character # # Modifiers can be added between the % and the pattern character to control the minimum width, maximum width, and alignment of the text. Such as: # %5c: output category name, the minimum width is 5, category<5, right-aligned by default # %-5c: Output category name, the minimum width is 5, category<5, "-" sign specifies left alignment, there will be spaces # %.5c: Output category name, the maximum width is 5, category>5, the extra characters on the left will be truncated, <5 will not have spaces # %20.30c:category name < 20 fill spaces, and right-aligned, > 30 characters, truncate the characters that are exported from the left ################################################################################ ################################################################################ #④Specify the output specific level of a specific package #log4j.logger.org.springframework=DEBUG ################################################################################ #OFF,systemOut,logFile,logDailyFile,logRollingFile,logMail,logDB,ALL log4j.rootLogger =ERROR,logFile # output to console #log4j.appender.systemOut = org.apache.log4j.ConsoleAppender #log4j.appender.systemOut.layout = org.apache.log4j.PatternLayout #log4j.appender.systemOut.layout.ConversionPattern = [%-5p][%-22d{yyyy/MM/dd HH:mm:ssS}][%l]%n%m%n #log4j.appender.systemOut.Threshold = DEBUG #log4j.appender.systemOut.ImmediateFlush = TRUE #log4j.appender.systemOut.Target = System.out # output to file log4j.appender.logFile = org.apache.log4j.FileAppender log4j.appender.logFile.layout = org.apache.log4j.PatternLayout log4j.appender.logFile.layout.ConversionPattern = [%-5p][%-22d{yyyy/MM/dd HH:mm:ssS}][%l]%n%m%n log4j.appender.logFile.Threshold = DEBUG log4j.appender.logFile.ImmediateFlush = TRUE log4j.appender.logFile.Append = TRUE log4j.appender.logFile.File = ../logs/test.log log4j.appender.A2.MaxBackupIndex=2 log4j.appender.logFile.Encoding = UTF-8 #Press DatePattern to output to file #log4j.appender.logDailyFile = org.apache.log4j.DailyRollingFileAppender #log4j.appender.logDailyFile.layout = org.apache.log4j.PatternLayout #log4j.appender.logDailyFile.layout.ConversionPattern = [%-5p][%-22d{yyyy/MM/dd HH:mm:ssS}][%l]%n%m%n #log4j.appender.logDailyFile.Threshold = DEBUG #log4j.appender.logDailyFile.ImmediateFlush = TRUE #log4j.appender.logDailyFile.Append = TRUE #log4j.appender.logDailyFile.File = ../test.log #log4j.appender.logDailyFile.DatePattern = '.'yyyy-MM-dd-HH-mm'.log' #log4j.appender.logDailyFile.Encoding = UTF-8 #Set the file size to output to a file #log4j.appender.logRollingFile = org.apache.log4j.RollingFileAppender #log4j.appender.logRollingFile.layout = org.apache.log4j.PatternLayout #log4j.appender.logRollingFile.layout.ConversionPattern = [%-5p][%-22d{yyyy/MM/dd HH:mm:ssS}][%l]%n%m%n #log4j.appender.logRollingFile.Threshold = DEBUG #log4j.appender.logRollingFile.ImmediateFlush = TRUE #log4j.appender.logRollingFile.Append = TRUE #log4j.appender.logRollingFile.File = ../test.log #log4j.appender.logRollingFile.MaxFileSize = 1MB #log4j.appender.logRollingFile.MaxBackupIndex = 10 #log4j.appender.logRollingFile.Encoding = UTF-8
Log4j logs
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326778589&siteId=291194637
Ranking