springboot集成logback-spring.xml日志文件
logback-spring.xml:
<!-- Logback configuration. See http://logback.qos.ch/manual/index.html --> <configuration scan="true" scanPeriod="10 seconds"> <springProperty scope="context" name="logLevel" source="log.level"/> <springProperty scope="context" name="logPath" source="log.path"/> <!-- Simple file output --> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <encoder> <pattern>%d{yy-MM-dd HH:mm:ss.sss} [%thread] %-5level %logger - %X{trackInfo} %msg%n</pattern> <charset>UTF-8</charset> <!-- 此处设置字符集 --> </encoder> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- rollover daily 配置日志所生成的目录以及生成文件名的规则 --> <fileNamePattern>${logPath}/log-%d{yyyy-MM-dd}.%i.log</fileNamePattern> <!--日志文件保留天数--> <MaxHistory>10</MaxHistory> <!--每个文件最多64MB,保留10天的历史记录,但最多10GB--> <TotalSizeCap>10GB</TotalSizeCap> <!--控制是否在项目启动的时候检查是否需要删除归档日志。--> <CleanHistoryOnStart>true</CleanHistoryOnStart> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <!-- 每个文件最多 64 MB --> <maxFileSize>64 MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> </appender> <!-- Console output --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder --> <encoder> <pattern>%d{yy-MM-dd HH:mm:ss.sss} [%thread] %-5level %logger \(%file:%line\) - %X{trackInfo} %msg%n</pattern> <charset>UTF-8</charset> <!-- 此处设置字符集 --> </encoder> </appender> <logger name="jndi" level="WARN" /> <logger name="org.eclipse" level="WARN" /> <logger name="org.springframework" level="WARN" /> <logger name="org.mybatis" level="WARN"/> <logger name="org.thymeleaf" level="WARN"/> <logger name="com.zaxxer.hikari" level="WARN"/> <logger name="com.corundumstudio.socketio" level="WARN"/> <logger name="io.netty.handler.codec.http.websocketx" level="WARN"/> <logger name="org.apache.shiro.web.servlet.SimpleCookie" level="WARN"/> <root level="${logLevel}"> <appender-ref ref="FILE" /> <appender-ref ref="STDOUT" /> </root> </configuration>