logback配置文件详解

时间:2021-09-10 16:30:06
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="10000" debug="false">

<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>

<!-- To enable JMX Management -->
<jmxConfigurator/>

<appender name="monitorFile"
class="ch.qos.logback.core.rolling.RollingFileAppender">

<file>${log.dir}/logs/nono-web-monitor.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.dir}/logs/nono-web-monitor.%d{yyyy-MM-dd}.log.zip
</fileNamePattern>
</rollingPolicy>

<encoder>
<pattern>%date %-5level|%-40.40logger{0}|%msg%n</pattern>
</encoder>
</appender>


<logger name="com.dzy.welfare" level="INFO" additivity="false">
<appender-ref ref="welfareFile"/>
</logger>

<logger name="org.springframework.data" level="INFO"/>
<logger name="org.apache.tomcat.util" level="ERROR"/>
<logger name="org.eclipse.jetty.util" level="ERROR"/>
<logger name="org.eclipse.jetty.http" level="ERROR"/>
<logger name="org.eclipse.jetty.annotations" level="ERROR"/>
<logger name="org.eclipse.jetty.webapp" level="ERROR"/>

<logger name="org.springframework.beans" level="INFO"/>
<logger name="JPM.Service" level="TRACE" additivity="false">
<appender-ref ref="monitorFile"/>
</logger>
<logger name="JPM.Repository" level="TRACE" additivity="false">
<appender-ref ref="monitorFile"/>
</logger>

<logger name="org.apache.activemq" level="ERROR" additivity="false">
<appender-ref ref="monitorFile"/>
</logger>

<!--打印sql用-->
<!-- <logger name="com.ibatis" level="DEBUG" />
<logger name="com.ibatis.common.jdbc.SimpleDataSource" level="DEBUG" />
<logger name="com.ibatis.common.jdbc.ScriptRunner" level="DEBUG" />
<logger name="com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate" level="DEBUG" />
<logger name="java.sql.Connection" level="DEBUG" />
<logger name="java.sql.Statement" level="DEBUG" />
<logger name="java.sql.PreparedStatement" level="DEBUG" />
<logger name="dao" level="DEBUG"/> -->


<root level="INFO">
<appender-ref ref="monitorFile"/>
<appender-ref ref="creditFile"/>
</root>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders 作用是将logger事件转换成字节数组,并将字节数组写入到输出流-->
<encoder>
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度 %msg:日志消息,%n是换行符-->
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

</configuration>