SDK日志輸出
更新時間:
程序調(diào)試過程中日志輸出配置
step 1:pom.xml中加入java sdk的依賴,如果已經(jīng)加入,請忽略. 另外加入以下依賴:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
</dependency>
step 2:將以下內(nèi)容保存為log4j.xml, 文件放在classpath的根目錄下.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%t] %c{1} - %m%n" />
</layout>
</appender>
<appender name="logfile" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="log/sdk.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %p [%c] - %m%n" />
</layout>
</appender>
<logger name="com.aliyun.opensearch">
<level value="debug" />
</logger>
<logger name="org.apache.thrift">
<level value="error" />
</logger>
<root>
<level value="info" />
<appender-ref ref="console" />
<appender-ref ref="logfile" />
</root>
</log4j:configuration>
step 3:(optional)改變?nèi)罩据敵鑫募奈恢胠og4j.xml文件中
<param name="File" value="log/sdk.log" />
把value改為目標路徑.
文檔內(nèi)容是否對您有幫助?