效果图
logback.xml文件配置
<configuration debug="false">
<!--日志输出到文件-->
<appender name="BaseLogFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/logback.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/archive/%d/%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>360</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d %msg %X{logthreadid} %n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<!--命令行输出的所有日志-->
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %-5level %20logger{0} %msg - n:%L %X{logthreadid} %n</pattern>
</encoder>
</appender>
<!--输出sql需要这一句-->
<logger name="com.example.my_spring2_chat" level="DEBUG">
<!-- <appender-ref ref="Console"/>-->
<appender-ref ref="BaseLogFile"/>
</logger>
<root level="info">
<appender-ref ref="Console"/>
</root>
</configuration>