application.properties配置:
logging.config=classpath:logback.xml logging.path=logs/youpath
logback.xml配置:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <!--<property resource="logback.properties" />--> <appender name="Console" class="ch.qos.logback.core.ConsoleAppender"> <Target>System.out</Target> <encoder> <pattern>%d [%t] %p %logger - %m%n</pattern> </encoder> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>DEBUG</level> </filter> </appender> <appender name="LogFile" class="ch.qos.logback.core.rolling.RollingFileAppender"> <Append>true</Append> <encoder> <pattern>%d [%t] %p %logger{0} - %m%n</pattern> </encoder> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>INFO</level> </filter> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${log.path}/xxx-log.%d{yyyy-MM-dd}.log</fileNamePattern> <maxHistory>30</maxHistory> </rollingPolicy> </appender> <appender name="ErrorFile" class="ch.qos.logback.core.rolling.RollingFileAppender"> <encoder> <pattern>%d [%t] %p %logger{0} - %m%n</pattern> </encoder> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>ERROR</level> </filter> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${log.path}/xxx-error.%d{yyyy-MM-dd}.log</fileNamePattern> <maxHistory>30</maxHistory> </rollingPolicy> </appender> <!--<logger name="org.springframework" level="DEBUG"/>--> <!--<logger name="org.apache" level="DEBUG"/>--> <!--<logger name="org.mybatis.spring" level="DEBUG"/>--> <root level="INFO"> <appender-ref ref="Console"/> <appender-ref ref="LogFile"/> <appender-ref ref="ErrorFile"/> </root> </configuration>