Spring boot application.properties provides the configuration of the logs, but I'm still accustomed to the way the old logback are used. The following describes how to use the custom Logback in Springboot.
1, in the Src/main/resources directory to create the Logback.xml file, the contents are as follows:
<!--logback configuration. See http://logback.qos.ch/manual/index.html -<ConfigurationScan= "true"Scanperiod= "Ten Seconds"> <includeResource= "Org/springframework/boot/logging/logback/base.xml" /> <Appendername= "Info_file"class= "Ch.qos.logback.core.rolling.RollingFileAppender"> <File>${log_path}/info.log</File> <Rollingpolicyclass= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <Filenamepattern>${log_path}/info-%d{yyyymmdd}.log.%i</Filenamepattern> <Timebasedfilenamingandtriggeringpolicyclass= "Ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <MaxFileSize>500MB</MaxFileSize> </Timebasedfilenamingandtriggeringpolicy> <maxhistory>2</maxhistory> </Rollingpolicy> <Layoutclass= "Ch.qos.logback.classic.PatternLayout"> <Pattern>%d{yyyy-mm-dd HH:mm:ss. SSS} [%thread]%-5level%logger{36}-%msg%n</Pattern> </Layout> </Appender> <Appendername= "Error_file"class= "Ch.qos.logback.core.rolling.RollingFileAppender"> <Filterclass= "Ch.qos.logback.classic.filter.ThresholdFilter"> < Level>ERROR</ Level> </Filter> <File>${log_path}/error.log</File> <Rollingpolicyclass= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <Filenamepattern>${log_path}/error-%d{yyyymmdd}.log.%i</Filenamepattern> <Timebasedfilenamingandtriggeringpolicyclass= "Ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <MaxFileSize>500MB</MaxFileSize> </Timebasedfilenamingandtriggeringpolicy> <maxhistory>2</maxhistory> </Rollingpolicy> <Layoutclass= "Ch.qos.logback.classic.PatternLayout"> <Pattern>%d{yyyy-mm-dd HH:mm:ss. SSS} [%thread]%-5level%logger{36}-%msg%n</Pattern> </Layout> </Appender> <!--Hibernate log Input - <Loggername= "Org.hibernate.type.descriptor.sql.BasicBinder" Level= "TRACE" /> <Loggername= "Org.hibernate.type.descriptor.sql.BasicExtractor" Level= "TRACE" /> <Loggername= "Org.hibernate.SQL" Level= "DEBUG" /> <Loggername= "Org.hibernate.engine.QueryParameters" Level= "DEBUG" /> <Loggername= "Org.hibernate.engine.query.HQLQueryPlan" Level= "DEBUG" /> <Root Level= "INFO"> <Appender-refref= "Info_file" /> <Appender-refref= "Error_file" /> </Root> </Configuration>
2. Specify the path of Logback.xml and log generation in Application.properties, as follows:
logging.config=Classpath:logback.xmllogging.path=/workspace/rock/jpa-test/log
Spring Boot Log configuration