程序调试过程中日志输出配置
step 1:pom.xml中加入java sdk的依赖,如果已经加入,请忽略. 另外加入以下依赖:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
</dependency>
step 2:将以下内容保存为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)改变日志输出文件的位置log4j.xml文件中
<param name="File" value="log/sdk.log" />
把value改为目标路径.
文档内容是否对您有帮助?