Spring Boot 日志分开存储

本文介绍了如何在Spring Boot项目中实现日志分开存储,避免控制台输出混乱。通过引入logback依赖,并配置logback-spring.xml文件,详细讲解了配置过程。
摘要由CSDN通过智能技术生成

背景说明

程序中逻辑比较复杂,写了很多日志,但是不想让控制台很混乱,于是就配置了info,error,debug日志记录。

引入依赖

正常来说,需要引入依赖:

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

编写配置文件

文件名:logback-spring.xml
位置: resources

参考如下:


<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="10 seconds">

    <contextName>logback</contextName>

    <springProperty scope="context" name="logPath" source="logging.file.path"/>

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <target>System.out</target>
        <!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>debug</level>
        </filter>
        <encoder>
            <pattern
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值