rocketmq默认不使用logback日志,所以得额外配置,使mq使用logback配置
-
使用logback中的日志配置
配置MQ
使用logback的配置,具体原理见ClientLogger.java的static代码块
在应用启动函数中添加如下代码
System.*setProperty*(ClientLogger.*CLIENT_LOG_USESLF4J*, "true");
-
修改logback-spring.xml,配置日志级别到error级别
<!-- RocketMQ日志 -->
<appender name="RocketmqClientAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/rocketmq/rocketmq_client.log</file>
<append>true</append>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${LOG_DIR}/rocketmq/rocketmq_client.%i.log</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>10</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>64MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%d{yyy-MM-dd HH:mm:ss,GMT+8} %p %t - %m%n</pattern>
<charset class="java.nio.charset.Charset">UTF-8</charset>
</encoder>
</appender>
<!-- 生产环境:输出到文档-->
<springProfile name="prod">
<logger name="RocketmqCommon" additivity="false" level="ERROR">
<appender-ref ref="RocketmqClientAppender"/>
</logger>
<logger name="RocketmqRemoting" additivity="false" level="ERROR">
<appender-ref ref="RocketmqClientAppender"/>
</logger>
<logger name="RocketmqClient" additivity="false" level="ERROR">
<appender-ref ref="RocketmqClientAppender"/>
<appender-ref ref="CONSOLE"/>
</logger>
</springProfile>