spring boot logging日志配置注意事项

控制台日志输入级别设置:在application.ym增加以下内容

logging:
  level:
    root: INFO #系统日志配置为info
    com.macro.mall: DEBUG #程序日志设置为debug

将控制台信息按每日切分输出到日志文件:在logback-spring.xml配置问下内容

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
        <destination>localhost:4560</destination>
        <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder" />
    </appender>
    <!--按天生成日志-->
    <appender name="logFile"  class="ch.qos.logback.core.rolling.RollingFileAppender">
          <Prudent>true</Prudent>
          <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
               <!-- 保存日志文件路径 -->
               <FileNamePattern>
                    D:/spring_web/poslog/%d{yyyy-MM-dd}/%d{yyyy-MM-dd}.log
               </FileNamePattern>
          </rollingPolicy>
          <layout class="ch.qos.logback.classic.PatternLayout">
               <!-- 日志输出格式 -->
               <Pattern>
                %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
               </Pattern>
          </layout>
    </appender>
    <!-- 需将appender节点配置到此处 -->
    <root level="INFO">
        <appender-ref ref="LOGSTASH" />
        <appender-ref ref="logFile" />
    </root>
</configuration>

你可能感兴趣的:(spring,boot,后端开发学习)