Detailed log file configuration

#Log root configuration, DEBUG is the log level, CONSOLE, FILE, ROLLING_FILE is the log output location
log4j.rootLogger=DEBUG,CONSOLE,FILE,ROLLING_FILE #Output
Jdbc sql statement
log4j.logger.org.springframework.jdbc.core.JdbcTemplate=INFO #The
encoding method of the log output file is UTF-8
log4j.appender.file.encoding=UTF-8




#org.apache.log4j.ConsoleAppender (console),  
#org.apache.log4j.FileAppender (file),  
#org.apache .log4j.DailyRollingFileAppender (generates a log file every day),  
#org.apache.log4j.RollingFileAppender (generates a new file when the file size reaches the specified size),  
#org.apache.log4j.WriterAppender (writes log information in stream format) Send to any specified place) #Console
output configuration
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender #Global
filter, filter information lower than INFO and not display, only display information above INFO and INFO level
log4j. appender.CONSOLE.Threshold=INFO
#Output logs in the form of system standard output, similar to the output of System.out in the code
log4j.appender.CONSOLE.Target=System.out #Define
the display layout, here is a simple layout, you cannot customize
log4j.appender.CONSOLE.layout= org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern= mytest %p ​​%d{yyyy MMM dd HH:mm:ss,SSS} [%t] %C.%M(%L)>>% m%n
#%p: The priority of output log information, namely DEBUG, INFO, WARN, ERROR, FATAL.
#%d: The date or time of the output log time point. The default format is ISO8601. You can also specify the format after it, such as: %d{yyyy/MM/dd HH:mm:ss,SSS}.
#%r: The number of milliseconds it took to output the log information since the application was started.
#%t: Output the thread name that generated the log event.
#%l: Output the location of the log event, which is equivalent to the combination of %c.%M (%F:%L), including the full class name, method, file name, and the number of lines in the code. For example: test.TestLog4j.main(TestLog4j.java:10).
#%c: The category to which the output log information belongs, usually the full name of the category.
#%M: Output the name of the method that generates log information.
#%F: The name of the file where the output log message was generated.
#%L::: The line number in the output code.
#%m::: Output the specific log information specified in the code.
#%n: Output a carriage return line feed, "rn" for Windows platforms and "n" for Unix platforms.
#%x: Output the NDC (Nested Diagnostic Environment) associated with the current thread, especially for multi-client multi-threaded applications like java servlets.
#%%: Output a "%" character.
#In addition, you can also add modifiers between % and the format character to control its minimum length, maximum length, and text alignment. Such as:
#1) c: Specify the name of the output category. The minimum length is 20. If the length of the category name is less than 20, it will be right-aligned by default.
#2)%-20c: "-" sign indicates left alignment.
#3)%.30c: Specify the name of the output category. The maximum length is 30. If the length of the category name is greater than 30, the extra characters on the left will be truncated, but if it is less than 30, no spaces will be added.


#Log file output configuration
log4j.appender.FILE=org.apache.log4j.FileAppender #Global
filter, the information below INFO is not displayed, only the information above INFO and INFO level is displayed
log4j.appender.FILE.Threshold=INFO
#Configure the relative location of the log file, /logs/file.log under the root directory location of the mytest project
log4j.appender.FILE.File=${mytest.root}/logs/file.

log4j.appender.FILE.Append=true
#When the log file reaches this size, it will automatically scroll, that is, move the original content to the file.log.1 file
log4j.appender.FILE.MaxFileSize=10Mb #Specify the
generated The maximum number of scrolling files
log4j.appender.FILE.MaxBackupIndex=5 #Define the
display layout, here is a simple layout, you cannot customize
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE. layout.ConversionPattern= %d - %c -%-4r [%t] %-5p %c %x - %m%n #Rollback


log file configuration
log4j.appender.ROLLING_FILE=org.apache.log4j.RollingFileAppender
log4j. appender.ROLLING_FILE.Threshold=ERROR
log4j.appender.ROLLING_FILE.File=${mytest.root}/logs/rolling.log
log4j.appender.ROLLING_FILE.Append=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 - %c -%-4r [%t] %-5p %c %x - %m%n

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325759414&siteId=291194637