Spring Boot boot process parsing logback

Source: Internet
Author: User

Use the Spring Boot default log frame Logback.

The benefit of all these POM dependencies is that it provides a good basis for developing Spring applications. The third-party library selected by Spring Boot is considered and is a better choice for product development. But Spring Boot also offers different options, such as the log framework can be used with logback or log4j, and the application server can use Tomcat or Jetty.
http://www.ibm.com/developerworks/cn/java/j-lo-spring-boot/

Color log implementation in spring boot

When you start the Spring boot application in the shell, it's interesting to see that its logger output is colored.

This setting can be used to turn off:

spring.output.ansi.enabled=false

The principle is to get this configuration through Ansioutputapplicationlistener, and then set the Logback in the output, add a colorconverter, Some of the fields are rendered by org.springframework.boot.ansi.AnsiOutput.

Gets the PID of the process

Applicationpid, the PID can be obtained.

    Private StringGetpid(){Try{String Jvmname= Managementfactory.Getruntimemxbean().getname (return jvmname. Split ([0  catch  (throwable ex{return null; } }        /span>                
Packaging Logger Class

Spring boot in the packaging of a set of logger, support for Java, log4j, Log4j2, Logback, after the need for their own packaging logger, can refer to this.

Under the Org.springframework.boot.logging package.

Gets the original Startup main function

The main function is determined by the method obtained in the stack, and the main function of the original startup is found.

Private Class<?>Deducemainapplicationclass(){Try{stacktraceelement[] StackTrace=NewRuntimeException().Getstacktrace();For(Stacktraceelement stacktraceelement: StackTrace){If("Main".equals(stacktraceelement.Getmethodname())){Return Classforname (stacktraceelement getclassname (} } } catch  (classnotfoundexception ex< Span class= "token punctuation") {//Swallow and Continue } return null              /span>         

Https://yq.aliyun.com/articles/6056?spm=5176.100240.searchblog.20.i049N1#2

Http://www.cnblogs.com/wangdaijun/p/5446924.html

Spring Boot boot process parsing logback

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.