百度智能云

All Product Document

          MapReduce

          Log

          Overview

          In the released version of BMR Java SDK, the logback is added as the realization of slf4j. You can directly use logback if you have no realization. The logback can replace log4j and other realizations in the project.

          Default Log

          If using the default logback, you need to configure logback.xml into the classpath. The log level is DEBUG, if you do not have the configuration file.

          <configuration>
              <property name="LOG_HOME" value="./log/"/>
              <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
                  <!-- encoders are assigned the type
                       ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
                  <encoder>
                      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
                  </encoder>
              </appender>
          
              <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
                  <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                      <FileNamePattern>${LOG_HOME}/BosUnitTest.%d{yyyy-MM-dd}.log</FileNamePattern>
                      <MaxHistory>30</MaxHistory>
                  </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>
                  <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
                      <MaxFileSize>10MB</MaxFileSize>
                  </triggeringPolicy>
              </appender>
          
              <root level="info">
                  <appender-ref ref="STDOUT"/>
                  <appender-ref ref="FILE"/>
              </root>
          </configuration>

          Private Log Module

          If using the private log realization module (such as project dependent on Maven), you can remove logback through the following similar configuration into pom.xml.

          <?xml version="1.0" encoding="utf-8"?>
          
          <dependency>      
            <groupId>com.baidubce</groupId>      
            <artifactId>bce-java-sdk</artifactId>      
            <version>${bce.sdk.version}</version>      
            <exclusions>        
              <exclusion>          
                <groupId>ch.qos.logback</groupId>          
                <artifactId>logback-classic</artifactId>        
              </exclusion>        
              <exclusion>          
                <groupId>ch.qos.logback</groupId>          
                <artifactId>logback-core</artifactId>        
              </exclusion>        
              <exclusion>          
                <groupId>org.slf4j</groupId>          
                <artifactId>jcl-over-slf4j</artifactId>        
              </exclusion>      
            </exclusions>    
          </dependency>
          Previous
          Step
          Next
          BmrClient