<?xml version= ' 1.0 ' encoding= ' UTF-8 '?> <! DOCTYPE log4j:configuration SYSTEM "Log4j.dtd" > <log4j:configuration xmlns:log4j= "http://jakarta.apache.org/ log4j/"> <appender name=" CONSOLE "class=" Org.apache.log4j.ConsoleAppender "> <layout class=" Org.ap Ache.log4j.PatternLayout "> <param name=" Conversionpattern "value="%d{yyyy-mm-dd HH:mm:ss} [%7r]%-5p%c %m:%l-%m%n "/> </layout> </appender> <appender name=" File-debug "class=" Org.apache.log 4j. Dailyrollingfileappender "> <param name=" datepattern "value=" '. '
YyyyMMdd "/> <param name=" Append "value=" true "/> <param name=" Threshold "value=" DEBUG "/> <param name= "Encoding" value= "UTF-8"/> <param name= "file" value= "${profile.log.root.path}/${profile
. Log.name.web}/${profile.log.name.web}-debug.log "/> <layout class=" Org.apache.log4j.PatternLayout "> <param name= "CoNversionpattern "value="%d{yyyy-mm-dd HH:mm:ss} [%7r]%-5p%c%m:%l-%m%n "/> </layout> </appender > <category name= "com.portal.controller" <strong><span style= "color: #ff6666;" >additivity= "false" </span></strong>> <priority value= "INFO"/> <appender-ref ref = "CONSOLE"/> </category> <root> <priority value= "INFO"/> <appender-ref re f= "CONSOLE"/> <appender-ref ref= "File-debug"/> </root> </log4j:configuration>
Public String index (model model) {
logger.info ("Log Test");
return null;
}
Test results:
1, do not write the root tag, only write category tags
Output Result: Test log
2. Write the root tag and category,category attribute additivity= "false"
Output Result: Test log
3. Write the root tag and Category,category properties additivity= "true"
Output results: Test log test logs
4, do not write category, only write root
Output Result: Test log
5, do not write
does not output any logs
6, write root, do not write category, but Root does not write <appender-ref ref= "CONSOLE"/>
No logs are output in the console
7, do not write root, write Category,category property additivity= "false"
Output Result: Test log
Description: The category attribute additivity= "false" means that the definition of log output in category is filtered out in root
Summarize:
The category name, which specifies the control of the log under a package, can be printed according to the business logic of the log classification output
Root is the log that controls the entire project.
Both the root and category are executed through the <appender-ref ref= "CONSOLE"/> To perform the log policy in the specific Appender, which Appender performs which
Root and category are parent-child relationships, root tags can not be written, category can also not write, but must write a
The category attribute additivity= "false" means that the definition of log output in category is filtered out in root
Other:
Category name, log classification output printing according to business logic
For example: Define name = "Usermanagerlog", then Logmanager.getlogger ("Usermanagerlog") in the code to introduce logs to the business related to user management.
You can hit a file by controlling the log of a business logic