更新时间:2024-03-07 GMT+08:00
分享

日志处理

logger名称和描述

Rainbow SDK需要配置的logger名称和描述如表1所示。

表1 logger说明

Logger名称

建议日志级别

说明

com.huawei.rainbow

com.huawei.wisecloud.jetcd

INFO

Rainbow SDK运行日志,建议打开,方便定位问题。

com.huawei.dcg.rainbow.switch

INFO

Rainbow双云状态大数据日志。

com.huawei.dcg.rainbow.access

INFO

Rainbow SDK接入大数据日志。

日志文件配置样例

  • logback.xml

    主要配置appender和logger,业务可以根据需要配置。

    file属性需要根据业务的路径进行配置。

    <appender name="RAINBOW_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>../log/rainbow/rainbow.log</file>  <!-- 路径自己配置-->
            <encoder>
                <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS}| [%thread]|%-5level|[%file:%line]|%p|%msg%n</pattern>
            </encoder>
            <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
                <minIndex>1</minIndex>
                <maxIndex>10</maxIndex>
                <FileNamePattern>../log/rainbow/rainbow.log.%i</FileNamePattern>
            </rollingPolicy>
            <triggeringPolicy  class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
                <maxFileSize>20MB</maxFileSize>
            </triggeringPolicy>
    </appender>
    
    <appender name="RAIBOW_SWITCH_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>../log/rainbow/rainbow_switch.log</file>
            <encoder>
                <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS}|%p|%msg%n</pattern>
            </encoder>
            <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
                <minIndex>1</minIndex>
                <maxIndex>10</maxIndex>
                <FileNamePattern>../log/rainbow/rainbow_switch.log.%i</FileNamePattern>
            </rollingPolicy>
            <triggeringPolicy  class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
                <maxFileSize>20MB</maxFileSize>
            </triggeringPolicy>
    </appender>
    
    <appender name="RAIBOW_STAT_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>../log/rainbow/rainbow_stat.log</file>
            <encoder>
                <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS}|%p|%msg%n</pattern>
            </encoder>
            <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
                <minIndex>1</minIndex>
                <maxIndex>10</maxIndex>
                <FileNamePattern>../log/rainbow/rainbow_stat.log.%i</FileNamePattern>
            </rollingPolicy>
            <triggeringPolicy  class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
                <maxFileSize>20MB</maxFileSize>
            </triggeringPolicy>
    </appender>
    
    <logger name="com.huawei.rainbow" level="INFO" additivity="false">
                         <appender-ref ref="RAINBOW_LOG" />
    </logger>
    <logger name="com.huawei.wisecloud.jetcd" level="INFO" additivity="false">
                         <appender-ref ref="RAINBOW_LOG" />
    </logger>
    <logger name="com.huawei.dcg.rainbow.switch" level="INFO" additivity="false">
                         <appender-ref ref="RAIBOW_SWITCH_LOG" />
    </logger>
    <logger name="com.huawei.rainbow.stat" level="INFO" additivity="false">
                         <appender-ref ref="RAIBOW_STAT_LOG" />
    </logger>
  • log4j2.xml

    主要配置appender和logger:

    fileName属性需要根据业务的路径进行配置。
    <RollingRandomAccessFile name="rainbow_log"
                 fileName="${logDir}/rainbow/rainbow.log"
                 filePattern="${logDir}/rainbow/rainbow.log.%d{yyyy-MM-dd}">
                 <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|[%t]|%-5level|[%F:%L]|%p|%msg%n"/>
                 <Policies>
                     <TimeBasedTriggeringPolicy/>
                 </Policies>
    </RollingRandomAccessFile>      
    
    <RollingRandomAccessFile name="rainbow_stat"
                 fileName="${logDir}/rainbow/rainbow_stat.log"
                 filePattern="${logDir}/rainbow/rainbow_stat.log.%d{yyyy-MM-dd}">
                 <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%msg%n"/>
                 <Policies>
                     <TimeBasedTriggeringPolicy/>
                 </Policies>
    </RollingRandomAccessFile>
    
    <RollingRandomAccessFile name="rainbow_switch"
                 fileName="${logDir}/rainbow/rainbow_switch.log"
                 filePattern="${logDir}/rainbow/rainbow_switch.log.%d{yyyy-MM-dd}">
                 <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%msg%n"/>
                 <Policies>
                     <TimeBasedTriggeringPolicy/>
                 </Policies>
    </RollingRandomAccessFile>
    
    <Logger name="com.huawei.rainbow" level="INFO"  additivity="false"
                includeLocation="true">
                <AppenderRef ref="rainbow_log" />
    </Logger>
    <Logger name="com.huawei.wisecloud.jetcd" level="INFO"  additivity="false"
                includeLocation="true">
                <AppenderRef ref="rainbow_log" />
    </Logger>
    <Logger name="com.huawei.dcg.rainbow.switch" level="INFO"  additivity="false"
                includeLocation="true">
                <AppenderRef ref="rainbow_switch" />
    </Logger>
    <Logger name="com.huawei.rainbow.stat.RainbowStatFilter" level="info"  additivity="false"
                includeLocation="true">
                <AppenderRef ref="rainbow_stat" />
    </Logger>

相关文档