美文网首页
RocketMQ 客户端日志rocketmqclient.log

RocketMQ 客户端日志rocketmqclient.log

作者: liuliuzo | 来源:发表于2020-08-29 14:15 被阅读0次

    介绍

    Rocketmq 原生的客户端日志,可以通过JVM参数进行配置,项目中我们往往需要使用slf4j日志来管理应用的日志,这里介绍下RocketMQ 客户端日志集成Slf4j Logback日志的方法。

    原生Rocketmq 客户端日志Java option参数

    -Drocketmq.client.logUseSlf4j=true
    -Drocketmq.client.logFileMaxIndex=xxx
    -Drocketmq.client.logFileMaxSize=xxx
    -Drocketmq.client.logLevel=xxx
    -Drocketmq.client.log.additive=xxx
    -Drocketmq.client.logFileName=xxx
    -Drocketmq.client.logAsyncQueueSize=xxx
    

    添加logback.xml文件的logger

    <?xml version="1.0" encoding="UTF-8"?>
    <included>
        <springProperty scope="context" name="application.name" source="spring.application.name" />
        <springProperty scope="context" name="rocketmq.client.level" source="rocketmq.client.level" />
        <springProperty scope="context" name="rocketmq.client.path" source="rocketmq.client.path" />
     
        <!-- better integration unstructured log appender-->
        <appender name="RocketmqClientAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${rocketmq.client.path}/${application.name}_rocketmqclient.log</file>
            <encoder>
                <pattern>%date{ISO8601} %level %thread %logger{16} %msg%n</pattern>
            </encoder>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <fileNamePattern>${rocketmq.client.path}/${application.name}_rocketmqclient.%d{yyyy-MM-dd}.%i.zip</fileNamePattern>
                <maxHistory>30</maxHistory>
                <totalSizeCap>128GB</totalSizeCap>
                <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                    <maxFileSize>500MB</maxFileSize>
                </timeBasedFileNamingAndTriggeringPolicy>
            </rollingPolicy>
        </appender>
        <logger name="RocketmqRemoting" additivity="false" level="${rocketmq.client.level:-WARN}">
            <appender-ref ref="RocketmqClientAppender" />
        </logger>
        <logger name="RocketmqClient" additivity="false" level="${rocketmq.client.level:-WARN}">
            <appender-ref ref="RocketmqClientAppender" />
        </logger>
        <logger name="RocketmqCommon" additivity="false" level="${rocketmq.client.level:-WARN}">
            <appender-ref ref="RocketmqClientAppender" />
        </logger>
    </included>
    

    application.properties 文件中添加以下配置:

    rocketmq.client.path=your path (eg./data/appLogs/RMQClientlogs)
    rocketmq.client.level=DEBUG,WARN,INFO,ERROR
    

    客户端生效Slf4j日志

    方法1

    static {
     System.setProperty("rocketmq.client.logUseSlf4j","true");
    }
    

    方法2

    public class Application extends SpringBootServletInitializer {
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            System.setProperty("rocketmq.client.logUseSlf4j","true");
            return application.sources(Application.class);
        }
    }
    

    方法3

    //override "logUseSlf4j" by option Java option
    -Drocketmq.client.logUseSlf4j=true
    

    相关文章

      网友评论

          本文标题:RocketMQ 客户端日志rocketmqclient.log

          本文链接:https://www.haomeiwen.com/subject/sytjsktx.html