application.properties
logging.config=classpath:log/logback-dev.xml
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<property name="LOG_HOME" value="C:/logs/mobile" />
<property name="CONSOLE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss} %-5level %-40.40logger{39} : %m%n"/>
<property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss} %-5level %-40.40logger{39} : %m%n"/>
<!--输出到控制台-->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>error</level>
</filter>
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<!-- 按照每天生成日志文件 -->
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>debug</level>
</filter>
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
<charset>UTF-8</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<fileNamePattern>${LOG_HOME}/spread.%d{yyyy-MM-dd}.log</fileNamePattern>
<!--保留的日志文件个数,10个即10天-->
<MaxHistory>10</MaxHistory>
</rollingPolicy>
<!--日志文件最大的大小-->
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>50MB</MaxFileSize>
</triggeringPolicy>
</appender>
<!-- 日志输出级别 -->
<root level="DEBUG">
<!-- <appender-ref ref="CONSOLE" /> -->
<appender-ref ref="file"/>
</root>
<!-- 如果需要指定到包 -->
<!-- <logger name="com.xlkj.mobile.controller.traffic.TrafficOrderTaskController" level="error" additivity="false">
<appender-ref ref="CONSOLE" />
</logger> -->
</configuration>