Spring Boot 配置logback 保存日志信息

本文详细介绍了如何在Spring Boot应用中配置Logback,以实现日志信息的有效保存。通过完整的配置文件示例,读者将了解Logback在Spring Boot中的设置步骤和关键配置项。
摘要由CSDN通过智能技术生成
If you put a logback.xml in the root of your classpath, it is picked up from there (or from logback-spring.xml, to take advantage of the templating features provided by Boot). Spring Boot provides a default base configuration that you can include if you want to set levels, as shown in the following example:

官方推荐将配置文件命名为logback-spring.xml,可使用spring-boot特有配置

将logback-spring.xml放到resources文件夹下即可

完整配置文件

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!-- root的作用类似于logger父亲,它与logger的作用就是日志收集,过滤,委派给appender作日志输出 -->
    <!-- appender的作用是控制日志输出 -->
    <!-- encoder和layout的作用是控制日志输出格式 -->
    <!-- appender里面只需配置:(1)日志滚动策略(2)日志输出格式(3)过滤日志级别 -->

    <!-- 日志格式应用spring boot默认的格式 -->
    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>

    <!-- 定义日志的存放位置,与项目同级目录下创建一个college-minor-log文件夹 -->
    <property name="LOG_DIR" value="./college-minor-log"/>

    <!-- 控制台日志输出 -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoder 默认配置为PatternLayoutEncoder -->
        <encoder>
            <pattern>${CONSOLE_LOG_PATTERN}</pattern>
            <charset>utf-8</charset>
        </encoder>
    </appender>

    <!-- 配置info日志输出 -->
    <appender name="info_log
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值