配置文件以application.yml为例说明:html
Spring Boot默认的日志组件为Logback。web
一. 日志配置参数:spring
logging:
file: # 日志文件,绝对路径或相对路径
path: # 保存日志文件目录路径
config: # 日志配置文件,Spring Boot默认使用classpath路径下的日志配置文件,如:logback.xml
level: # 日志级别
org.springframework.web: DEBUG # 配置spring web日志级别
二. 更改Spring Boot日志组件为Log4j(注:Spring Boot仅仅支持Log4j 2.x版本):springboot
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency>
三. 关于Spring Boot日志文件路径的疑惑?
同时配置了logging.path和logging.file属性,以下配置:app
logging:
path: /var/log
file: test.log
仅仅只会在项目根路径下产生test.log文件,不会在指定路径下产生日志文件(指望日志路径为:logging.path + logging.file)。
spring-boot
缘由:Spring Boot中的logging.path和logging.file这2个属性,只须要配置其中之一便可,若是同时配置,则使用logging.file属性。spa
当配置了loggin.path属性时,将在该路径下生成spring.log文件,即:此时使用默认的日志文件名spring.log日志
当配置了loggin.file属性时,将在指定路径下生成指定名称的日志文件。默认为项目相对路径,能够为logging.file指定绝对路径。code
logging:
path: /var/logs # 在/var/logs目录下生成spring.log文件
file: /var/logs/test.log # 在/var/logs目录下生成test.log文件
详见:http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html xml
【参考】
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html
http://didispace.com/springbootlog/