Baidu AI Cloud
中国站

百度智能云

CDN

SDK Log-level Configuration

Logback is added to the version issued by Java SDK as the realization of slf4j, which can be used if you do not have their own realization, and if there are others like log4j in project, they can be replaced.

Default Log

If you use default logback, it needs to be configured in classpath of logback.xml. If there is no such configuration file, the log 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}/CdnUnitTest.%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> 

Own Log Module

If you use their own log realization module, for example, the project relies on Maven, it can be configured to pom.xml similarly as below to remove logback.

<?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
Tool Interface
Next
Version Change Record