转载

SpringBoot(七) SpringBoot整合Log4j

第一种打印debug日志方式:

logging.level.com.demo.mapper: debug

SpringBoot(七) SpringBoot整合Log4j

SpringBoot(七) SpringBoot整合Log4j

第二种打印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换成你自己的实际包名。重启项目,访问,查看控制台日志。

原文  https://www.maiyewang.com/2019/12/06/springboot(七)-springboot整合log4j-2/
正文到此结束
Loading...