您的位置:首页 > 编程语言 > Java开发

从零开始学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的身影。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring boot