springboot log configuration, on logback

1. dependence

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>

Spring Boot project usually referenced spring-boot-starteror spring-boot-starter-web, and the two started dependence have been included for spring-boot-starter-loggingdependency, therefore, no additional add-dependent.

You can view the jar package dependencies in maven idea upper right corner.

2. Use

About 2.1 Conventions

There are many things you need to configure the log, but it seems no need to configure anything, today's passage awoke me.

According to different log system, in accordance with the rules of the organization designated profile name, and placed under the resources directory can be automatically loaded spring boot:

  • Logback:logback-spring.xml, logback-spring.groovy, logback.xml, logback.groovy
  • Log4j: log4j-spring.properties, log4j-spring.xml, log4j.properties, log4j.xml
  • Log4j2: log4j2-spring.xml, log4j2.xml
  • JDK (Java Util Logging): logging.properties

The content is springboot advantage, and convention over configuration.

Want to customize the file name can be configured: logging.configspecify the configuration file name:

logging.config=classpath:logging-config.xml

pring Boot official recommended to use the file name with -spring as you log configuration (such as the use logback-spring.xml, rather than logback.xml), named logback-spring.xml log configuration file, spring boot can be add some spring boot-specific configuration items.

2.2 configuration file contents

Guess you like

Origin www.cnblogs.com/zhanghao1799/p/11947137.html