首页 > 技术文章 > logback

albert-think 2019-05-24 15:14 原文

一、logback-spring.xml
<?xml version="1.0" encoding="utf-8" ?>
<configuration scan="true" scanPeriod="10" debug="false">
<contextName>auto-project</contextName>

<!--输出到控制台-->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[auto-project] %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="com.sekorm.sps.autoproject.dao" additivity="true"/>
<!--输出到文件-->
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${catalina.home}/logs/auto-project/%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %msg%n</pattern>
</encoder>
</appender>

<springProfile name="prod">
<root level="DEBUG">
<appender-ref ref="file"/>
</root>
</springProfile>

<springProfile name="dev">
<root level="DEBUG">
<appender-ref ref="console"/>
</root>
</springProfile>

</configuration>

二、application.yml
server:
port: 8086

spring:
profiles:
active: prod

#mybatis
mybatis:
config-location: classpath:mybatis/mybatis-config.xml
mapper-locations: classpath:mybatis/mapper/*Mapper.xml
type-aliases-package: com.sekorm.sps.autoproject.entity
logging:
config: classpath:logback-spring.xml

推荐阅读