springboot 1.5.3.RELEASE + lombok
class上加上 lombok的 @Slf4j 注解,类中便可以直接使用 log.info() 等方法输出不同等级日志
resources文件夹下添加 logback-spring.xml 文件, 内容如下
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<contextName>logback</contextName>
<!--输出到控制台-->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<!-- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>-->
<encoder>
<pattern>%d{HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!--按天生成日志 文件夹为log可修改-->
<appender name="logFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<Prudent>true</Prudent>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>
log/%d{yyyy-MM-dd}.log
</FileNamePattern>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} -%msg%n
</Pattern>
</layout>
</appender>
<root level="INFO">
<appender-ref ref="console" />
<appender-ref ref="logFile" />
</root>
<!-- <logger name="com.pos" level="INFO" additivity="false">
<appender-ref ref="console"/>
</logger> -->
</configuration>
网友评论