1. 先配置maven
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
2.在下图目录中配置log4j
# 日记级别(单个级别) 文件/控制台 log4j.rootLogger=info, stdout,file # Redirect log messages to console log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n # Rirect log messages to a log file log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=test.log log4j.appender.file.MaxFileSize=5MB log4j.appender.file.MaxBackupIndex=10 log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
3. 使用log4j
public class Demo_01_base { private static final Logger logger = LoggerFactory.getLogger(Demo_01_base.class); static String accessToken; static int departmentId; @BeforeAll public static void getAccessToken(){ accessToken = given().log().all() .when() .param("corpid","ww1aa64e79931be685") .param("corpsecret","82N9nLXm5CH7ZtY6LgkWHYPgcS_yQESQXTYD_8iF_Lw") .get("https://qyapi.weixin.qq.com/cgi-bin/gettoken") .then().log().all() .extract().response().path("access_token"); logger.info(accessToken); } }