Spring Boot Log configuration

Source: Internet
Author: User

Step 1: Increase the Logback configuration file

Note: The name is Logback.xml or Logback-spring.xml, recommended is Logback-spring.xml, why. Because the Spring boot framework defaults to looking for a configuration named this, and adds some features.

Step 2:logback.xml Content Configuration

<?xml version= "1.1" encoding= "UTF-8"?> <configuration> <springproperty scope= "context" name= "LogPath" Source= "Logging.path"/> <springproperty scope= "context" name= "ServerName" source= "Server.name"/> <ap Pender name= "Console" class= "Ch.qos.logback.core.ConsoleAppender" > <encoder> <pattern>% Date|%thread|%x{invokeno}|%level|%logger{0}|%msg%n</pattern> </encoder> </appender> < Appender name= "Rollinginfofile" class= "Ch.qos.logback.core.rolling.RollingFileAppender" > <file>${logpath }/${servername}/${servername}.log</file> <rollingpolicy class= " Ch.qos.logback.core.rolling.FixedWindowRollingPolicy "> <filenamepattern>${logpath}/${servername}/${se Rvername}.%i.log</filenamepattern> <minIndex>1</minIndex> <maxIndex>10< /maxindex> </rollingPolicy> &LT;TRIGGERINGPOlicy class= "Ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy" > <maxfilesize>500mb</maxfilesi ze> </triggeringPolicy> <encoder> <pattern>%date|%thread|%x{invokeno}|%le vel|%logger{0}|%msg%n</pattern> </encoder> </appender> <logger name= "Com.alibaba" Level= "${logginglevel}" > <appender-ref ref= "rollinginfofile"/> </logger> <logger name= "Org.apache.ibatis" level= "${logginglevel}" > <appender-ref ref= "rollinginfofile"/> </logger>- -<root level= "${logginglevel}" > <appender-ref ref= "rollinginfofile"/> <appender- Ref ref= "Console"/> </root> </configuration> Note: <springproperty scope= "Context" name= "LogPath" Source= "Logging.path"/> <springproperty scope= "context" name= "ServerName" source= "Server.name"/>

Logging.path and Server.name are all variables that I've defined in the Applicaiton-{profile}.xml, so be sure to use Springproperty to refer to them, otherwise you won't be using them.

Oddly enough, Logginglevel is also defined in the configuration file, but this does not need to be brokered, and can be used directly through ${logginglevel.

Projects can be consulted: Https://github.com/BruceZhangXL/wolf

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.