The Logback configuration file for the Spring boot project uses the YAML format

Source: Internet
Author: User

1, normal spring project use Logback default with the properties file as a configuration variable.

2, if you want to use the Yaml file, then can be converted to spring boot project, natural seamless integration

3, no way, if the project configuration file with Yaml, then your logback can only open a separate properties file for individual configuration

The following is an example of a YAML configuration file based on spring boot:

APPLICATION.YML:

# log is configured  to be empty for the project and directory logs  or to specify an existing directory log  :path:/data/weblog/business/www.test.com

Logback-spring.xml:

<?xml version= "1.0" encoding= "UTF-8"?><!--Description:1.file naming and loading order about Logback. XML is loaded earlier than APPLICATION.YML, Logback-spring.xml later than application.yml Load If the Logback configuration requires the use of applicationThe attributes in the. yml need to be named Logback-spring.XML2. Logback uses application.the properties in yml use Springproperty to use Application.the value in YML can be set to the default value--><configuration scan= "true" scanperiod= "seconds" > <!--log basePath-<springproperty scope= "context" name= "LogPath" source= "Log.path" defaultvalue= "Logs"/><!--log name-to <property name= "Log_home" value= "${logpath}"/> <!--back log basePath--<property name= "Log_back_home" value= "${logpath}/backup"/> <property name= "SRVNAME" value= "Clsapi-co Nsole "/> <!--file Cut size--<property name=" MaxFileSize "value=" 100MB "/> <!--document retention days--&L T;property name= "maxhistory" value= "/> <!--documents Keep total size--<property name=" Totalsizecap "value=" 10GB "/ > <!--system service log-<appender name= "FILE"class= "Ch.qos.logback.core.rolling.RollingFileAppender" > <file>${LOG_HOME}/${SRVNAME}.log</file> & Lt;rollingpolicy class= "Ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy" > <!--daily Rollover- <filenamepattern>${log_back_home}/%d{yyyy-mm-dd}/${srvname}.%d{hh}.%i.log.gz</filenamepattern&gt            ;            <!--single log file up to 100MB, 60-day log cycle, max. 10GB--<maxFileSize>${maxFileSize}</maxFileSize> <maxHistory>${maxHistory}</maxHistory> <totalsizecap>${totalsizecap}</totalsizecap&gt        ; </rollingPolicy> <encoder> &LT;PATTERN&GT;%D{YYYYMMDD HH: Mm:ss. SSS}%x{log_id} [%thread]%-5level%logger{100}.%method\ (\):%l-%msg%n</pattern> </encoder> </ap pender> <appender name= "STDOUT" class= "Ch.qos.logback.core.ConsoleAppender" > <!-- onWindows machines Setting Withjansi to True enablesANSIcolor code interpretation by the Jansi library.This requires org. fusesource.jansi: Jansi: 1.8 onThe classPath.Note that unix-based operating systems such as Linux and Mac OS X SupportANSIColor codes by default.recognizes"%black", "%red", "%green", "%yellow", "%blue", "%magenta", "%cyan", "%white", "%gray", "%boldred", "%boldgreen", "%boldyellow", "%boldblue", "%boldmagenta" "%boldcyan", "%boldwhite" and "%highlight"          --> <!--withjansi>true</withjansi--> <encoder> <!--%d{yyyy-mm-dd HH: Mm:ss. SSS}-%5P ${pid:-} [%15.15t]%-40.40logger{39}:%m%n--> <pattern>%boldcyan (%d{yyyy-mm-dd HH: Mm:ss. SSS})-%boldred (%5p)%blue ([%10.10t])%magenta (%-35.35logger{20})%yellow (%2M)%green (%2L):%msg%n</pattern> <!--&LT;PATTERN&GT;%D{YYYYMMDDHHMMSS} [%thread] [%c%2M%2L]%-3p-%m%n</pattern>--> </encoder> </appender> <root level= "Info" > < Appender-ref ref= "STDOUT"/> <appender-ref ref= "FILE"/> </root> <logger name= "com.easonjim.c Lsapi.aspect.LogsAspect "level=" Debug "> <appender-ref ref=" api_call_file "/> </logger> <logg Er name= "org.springframework.web.servlet" level= "info"/> </configuration>

4, if you want to use the Yaml file, then you can only use absolute path, for example:

Logback-spring.xml Introduction File:

<property file= "${home}/configuration/application.yaml"/>

application.yaml:

Log_file:c:/logs

Logback-spring.xml using:

<appender name= "My_appender" class= "Ch.qos.logback.core.rolling.RollingFileAppender" >        <file>${ Log_file}</file>...</appender>

Logback-spring.xml Increased scan time:

<configuration scan= "true" scanperiod= "ten Seconds" >

Reference:

Https://stackoverflow.com/questions/42648195/how-to-set-logback-xml-properties-in-application-yaml

https://my.oschina.net/skyzwg/blog/915527

The Logback configuration file for the Spring boot project uses the YAML format

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.