Spring Boot Log configuration

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.