<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!--
If variable is not defined in system properties -> try to load it from application.properties
-->
<!-- 使用这个语句需要添加janino依赖 implementation 'org.codehaus.janino:janino:3.0.12' -->
<if condition='!isDefined("logs.dir")'>
<then>
<property resource="application.properties" />
</then>
</if>
<!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- <Encoding>UTF-8</Encoding> -->
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<!-- 按照每天生成日志文件 -->
<appender name="ROLLING-FILE-1"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- <Encoding>UTF-8</Encoding> -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- logs.dir直接定义在application.properties文件中即可,例如 logs.dir=D:/test-->
<FileNamePattern>${logs.dir}/ethiopia_telecom_%d{yyyy_MM_dd}.log</FileNamePattern>
<!-- 日志文件保留天数 一个月 -->
<maxHistory>720</maxHistory>
<!--<!–每个文件最大50MB–>-->
<!--<maxFileSize>50MB</maxFileSize>-->
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<!-- http://www.importnew.com/28541.html 采取异步写日志的方式而不让此次写日志发生磁盘IO,阻塞线程从而造成不必要的性能损耗 -->
<!-- 异步输出 -->
<appender name ="ASYNC" class= "ch.qos.logback.classic.AsyncAppender">
<!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
<discardingThreshold>0</discardingThreshold>
<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
<queueSize>256</queueSize>
<!-- 添加附加的appender,最多只能添加一个 -->
<appender-ref ref ="ROLLING-FILE-1"/>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="ASYNC" />
</root>
<!-- 框架的日志到error级别才输出 -->
<logger name="org.springframework" level="ERROR"/>
<!-- 项目的日志,debug以上的都输出 -->
<logger name="com.hengbao.ethiopiatelecomrecharge" level="DEBUG" />
</configuration>