从零开始学spring-boot(3)-集成logback日志
2016-10-31 22:36
645 查看
当连接数据库后,在执行的过程中难免会报错,因此一个好的日志管理是一个项目所必备的,springboot默认集成了logback日志,因此我们就从logback日志入手。
1.首先在resource路劲下创建logback-spring.xml文件作为logback个性化配置文件,springboot优先扫描*-spring.xml的文件,也可以创建logback.xml。然后配置不同的运行环境不同的日志输出级别,减少频繁修改配置文件的烦恼。
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="org.springframework.web" level="INFO"/>
<logger name="com.zity.springboot" level="TRACE"/>
<!-- 测试环境 -->
<springProfile name="test">
<logger name="org.springframework.web" level="INFO"/>
<logger name="com.zity.springboot" level="INFO" />
</springProfile>
<!-- 开发环境 -->
<springProfile name="dev">
<logger name="org.springframework.web" level="DEBUG"/>
<logger name="com.zity.springboot" level="DEBUG" />
</springProfile>
<!-- 生产环境. -->
<springProfile name="prod">
<logger name="org.springframework.web" level="ERROR"/>
<logger name="org.springboot.sample" level="ERROR" />
</springProfile>
</configuration>2.然后在application.properties文件中添加log日志文件的存放路径,有两种存放路径的方法,一种是存放绝对路径,logging.file = D:/log/logback.log另一种为相对路径的配置方法采用logging.path=/log/logback.log
3.我这里采用的是绝对路径的方式,启动程序后会在D盘log文件夹下发现logback.log的身影。
1.首先在resource路劲下创建logback-spring.xml文件作为logback个性化配置文件,springboot优先扫描*-spring.xml的文件,也可以创建logback.xml。然后配置不同的运行环境不同的日志输出级别,减少频繁修改配置文件的烦恼。
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="org.springframework.web" level="INFO"/>
<logger name="com.zity.springboot" level="TRACE"/>
<!-- 测试环境 -->
<springProfile name="test">
<logger name="org.springframework.web" level="INFO"/>
<logger name="com.zity.springboot" level="INFO" />
</springProfile>
<!-- 开发环境 -->
<springProfile name="dev">
<logger name="org.springframework.web" level="DEBUG"/>
<logger name="com.zity.springboot" level="DEBUG" />
</springProfile>
<!-- 生产环境. -->
<springProfile name="prod">
<logger name="org.springframework.web" level="ERROR"/>
<logger name="org.springboot.sample" level="ERROR" />
</springProfile>
</configuration>2.然后在application.properties文件中添加log日志文件的存放路径,有两种存放路径的方法,一种是存放绝对路径,logging.file = D:/log/logback.log另一种为相对路径的配置方法采用logging.path=/log/logback.log
3.我这里采用的是绝对路径的方式,启动程序后会在D盘log文件夹下发现logback.log的身影。
相关文章推荐
- 54. spring boot日志升级篇—logback【从零开始学Spring Boot】
- 13.7 SpringBoot集成日志系统logback的几个问题
- Spring Boot(十)Logback和Log4j2集成与日志发展史
- 54. spring boot日志升级篇—logback【从零开始学Spring Boot】
- Springboot+logback集成ELK处理日志实例
- 54. spring boot日志升级篇—logback【从零开始学Spring Boot】
- 54. spring boot日志升级篇—logback【从零开始学Spring Boot】
- 52. spring boot日志升级篇—log4j多环境不同日志级别的控制【从零开始学Spring Boot】
- 35. Spring Boot集成Redis实现缓存机制【从零开始学Spring Boot】
- springboot使用之三:springboot使用logback日志
- 50. spring Boot日志升级篇—log4j【从零开始学Spring Boot】(
- ELK(ElasticSearch, Logstash, Kibana)+ SuperVisor + Springboot + Logback 搭建实时日志分析平台
- 46. Spring Boot中使用AOP统一处理Web请求日志【从零开始学Spring Boot】
- 50. Spring Boot日志升级篇—log4j【从零开始学Spring Boot】
- 从零开始学spring-boot(4)-集成Mybatis
- Spring Boot 中的日志记录 logback
- Spring Boot基础教程5-日志配置-logback和log4j2
- 81. Spring Boot集成JSP疑问【从零开始学Spring Boot】
- 从零开始学spring-boot(2)-集成spring-data-jpa
- Spring Boot实战之配置使用Logback进行日志记录