百度智能云

All Product Document

          Cloud Compute Service

          Log

          It adds the logback as the implementation of slf4j in the BCC Java SDK release. If you do not have the own implementation, you can use the logback directly. If there is any other implementation in the project, such as log4j, it can be replaced.

          Default Logback

          If you use the default logback, you need to configure logback.xml to classpath. If this configuration file does not exist, the logback level is DEBUG by default.

          <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}/BccUnitTest.%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>

          Built-in Logback Module

          If you want to use the built-in logback to implement the module, for example, the project depends on Maven, you can configure it to pom.xml to remove the logback as follows.

          <?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
          zone
          Next
          Exception Handling