Recently made a project, want to print different logs to different files, configured as follows:
Log4j.rootcategory=debug, stdout Log4j.rootlogger=debug, stdout, FILE # # # # stdout # # # log4j.appender.stdout= Org.apache.log4j.ConsoleAppender Log4j.appender.stdout.target=system.out log4j.appender.stdout.layout=
Org.apache.log4j.PatternLayout Log4j.appender.stdout.layout.conversionpattern=%d{absolute}%5p-%m%n # # output File configuration # # #
Log4j.appender.file=org.apache.log4j.rollingfileappender Log4j.appender.file.append=true Log4j.appender.file.file=./logs/root.log Log4j.appender.file.threshold=debug log4j.appender.FILE.layout= Org.apache.log4j.PatternLayout log4j.appender.file.layout.conversionpattern=%d{yyyy-mm-dd HH:mm:ss} [%5p]-%c-%f (% L)-%m%n LOG4J.APPENDER.FILE.MAXFILESIZE=10MB # # # # # # # # # # # # # Log4j.logger.org.springframework=debug, Spring lo
G4j.logger.org.apache=debug Log4j.logger.org.apache.catalina=debug Log4j.logger.org.apache.commons.digester.digester=debug log4j.logger.org.apache.catalina.startup.tldconfig= DEBUG Log4j.logger.chb.test=debug # # # # Print to the corresponding log log # # # LOG4J.appender.spring=org.apache.log4j.rollingfileappender Log4j.appender.spring.append=true Log4j.appender.spring.file=./logs/spring.log Log4j.appender.spring.threshold=debug log4j.appender.spring.layout= Org.apache.log4j.PatternLayout log4j.appender.spring.layout.conversionpattern=%d{yyyy-mm-dd HH:mm:ss} [%5p]-%c-%f (%l)-%m%n LOG4J.APPENDER.SPRING.MAXFILESIZE=10MB
Initially define the Rootlog, print to the project Logs/root.log, and then give Org.springframework an individual named Spring, and then print to Logs/spring.log. However, the file is always printed out anyway. Later found to be the file output path problem, must use absolute path.
After this modification
Log4j.appender.file.file=d:/xxx/logs/root.log
Log4j.appender.spring.file=d:/xxx/logs/spring.log
XXX for the corresponding path. To print out the file.