The default logging framework used by Sprongboot is logback.
You can configure simple log properties in Application.properties, you can configure the Logback.xml format separately, and you can use log4j to manage it.
The following sections describe your own log configuration and how to use log4j for log management.
1. Your own log management configuration:
1.1 Modifying Application.properties
#配置日志logging. level.root=infologging.level.org.springframework.web=debuglogging.level.org.hibernate=error# Logging.path=d:\\demo1logging.file=d:\\springboot3\\log\\demo2.log
This simple and rude convenience
2. Using log4j Management
2.1 Modify the Pom.xml file, filter out the spring-boot-starter-logging, and add the spring-boot-starter-log4j dependency package.
<!--log4j - <Dependency> <groupId>Org.springframework.boot</groupId> <Artifactid>Spring-boot-starter</Artifactid> <Exclusions> <exclusion> <groupId>Org.springframework.boot</groupId> <Artifactid>Spring-boot-starter-logging</Artifactid> </exclusion> </Exclusions> </Dependency> <Dependency> <groupId>Org.springframework.boot</groupId> <Artifactid>spring-boot-starter-log4j</Artifactid> <version>1.3.8.RELEASE</version> </Dependency>
2.2 Create a new log4j.properties configuration file under the Resources directory
Configure info,error,console,debug four output formats.
Log4j.rootlogger=Info,error,console,debugLog4j.appender.console=org.apache.log4j.consoleappender log4j.appender.console.layout= Org.apache.log4j.PatternLayout log4j.appender.console.layout.conversionpattern=%d{yyyy-mm-dd-hh-mm} [%t] [%c] [%p] -%m%n log4j.logger.info=infolog4j.appender.info= Org.apache.log4j.dailyrollingfileappenderlog4j.appender.info.layout=org.apache.log4j.patternlayout LOG4J.APPENDER.INFO.LAYOUT.CONVERSIONPATTERN=%D{YYYY-MM-DD-HH-MM} [%t] [%c] [%p]-%m%n Log4j.appender.info.datepattern= '. ' Yyyy-mm-ddlog4j.appender.info.threshold = info Log4j.appender.info.append=true log4j.appender.info.file=d:// Springboot3/logs/api_services_info.loglog4j.logger.error=error log4j.appender.error= Org.apache.log4j.dailyrollingfileappenderlog4j.appender.error.layout=org.apache.log4j.patternlayout LOG4J.APPENDER.ERROR.LAYOUT.CONVERSIONPATTERN=%D{YYYY-MM-DD-HH-MM} [%t] [%c] [%p]-%m%n Log4j.appender.error.datepattern= '. ' Yyyy-mm-ddlog4j.appender.error.threshold = Error Log4j.appender.error.append=true log4j.appender.error.file=d://springboot3/logs/error/api_services_error.loglog4j.logger.debug= debuglog4j.appender.debug=org.apache.log4j.dailyrollingfileappenderlog4j.appender.debug.layout= Org.apache.log4j.PatternLayout log4j.appender.debug.layout.conversionpattern=%d{yyyy-mm-dd-hh-mm} [%t] [%c] [%p]-% m%n log4j.appender.debug.datepattern= '. ' Yyyy-mm-ddlog4j.appender.debug.threshold = DEBUG Log4j.appender.debug.append=true log4j.appender.debug.file=d:// Springboot3/logs/debug/api_services_debug.log
3. Declare the log and output log information in the class used.
The output results are as follows:
Springboot Log management + integrated log4j