SpringBoot(七) SpringBoot整合Log4j
第一种打印debug日志方式:
logging.level.com.demo.mapper: debug
第二种打印debug日志方式:
在resource文件夹下新建:logback.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>
<!--按天生成日志-->
<appender name="logFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<Prudent>true</Prudent>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>
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} -%msg%n
</Pattern>
</layout>
</appender>
<root level="debug,ERROR">
<appender-ref ref="console" />
<appender-ref ref="logFile" />
</root>
<!-- <logger name="com.pos" level="INFO" additivity="false">
<appender-ref ref="console"/>
</logger> -->
</configuration>
在application.properties中添加:
logging.level.com.kaigejav.project.dao=DEBUG
这里需要注意:将com.kaigejav.project.dao换成你自己的实际包名。重启项目,访问,查看控制台日志。
学海无涯 代码作伴