springboot 项目中控制台打印日志以及每天生成日志文件
1.控制台打印sql语句
只要在application.properties 中加入logging.level.xxxx=DEBUG就可以了。其中xxxx是你想监听的包路径
2.每天打印日志
首先在resource目录下新建文件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>
<!--按天生成日志-->
<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>