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