gpt4 book ai didi

java - RestAssured 外部文件日志记录

转载 作者:太空宇宙 更新时间:2023-11-04 09:25:53 26 4
gpt4 key购买 nike

在rest-assured中使用requestSpecBuilder,我在日志文件中获取日志两次。如何禁用此功能?

 @BeforeClass
public void initSpec() {




spec = new RequestSpecBuilder().setContentType(ContentType.JSON).setBaseUri(Utils.getHostName()).setAccept(ContentType.JSON)
.setContentType(ContentType.JSON)
.build();
}

我的日志文件如下所示:-

02:08:26.547 [main] INFO  com.agileapps.settings.controller.api.userpassword.U_UserPasswordControllerTest - Start of changePassword_CurrentNewPasswordSame
02:08:26.547 [main] INFO com.agileapps.settings.controller.api.userpassword.U_UserPasswordControllerTest - Start of changePassword_CurrentNewPasswordSame
02:08:26.553 [main] INFO com.agileapps.settings.controller.api.userpassword.U_UserPasswordControllerTest - URL: https://settings/user-password
02:08:26.553 [main] INFO com.agileapps.settings.controller.api.userpassword.U_UserPasswordControllerTest - URL: https://settings/user-password
02:08:27.641 [main] INFO com.agileapps.settings.controller.api.userpassword.U_UserPasswordControllerTest - End of changePassword_CurrentNewPasswordSame
02:08:27.641 [main] INFO com.agileapps.settings.controller.api.userpassword.U_UserPasswordControllerTest - End of changePassword_CurrentNewPasswordSame
02:08:27.643 [main] INFO com.agileapps.settings.controller.api.userpassword.U_UserPasswordControllerTest - Start of changePassword_CurrentPasswordNull
02:08:27.643 [main] INFO com.agileapps.settings.controller.api.userpassword.U_UserPasswordControllerTest - Start of changePassword_CurrentPasswordNull
02:08:27.644 [main] INFO com.agileapps.settings.controller.api.userpassword.U_UserPasswordControllerTest - URL: https://settings/user-password
02:08:27.644 [main] INFO com.agileapps.settings.controller.api.userpassword.U_UserPasswordControllerTest - URL: https://settings/user-password

log4j.xml 文件:-

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Properties>
<Property name="basePath">./logs</Property>
</Properties>

<Appenders>
<RollingFile name="File" fileName="${basePath}/Settings.log" filePattern="${basePath}/Re-EngineeringLogs-%d{yyyy-MM-dd}.log">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<SizeBasedTriggeringPolicy size="250000000" />
</RollingFile>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="com.agileapps.settings.test.employee.PostObject" level="trace">
<AppenderRef ref="File"/>
</Logger>
<Root level="info">
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>

但是由于添加了方法 initSpec(),我收到了此错误,如上所示。

最佳答案

我通过更改 log4j.xml 文件修复了解决方案:-

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Properties>
<Property name="basePath">./logs</Property>
</Properties>

<Appenders>
<RollingFile name="AgileAppsFileAppender"
fileName="${basePath}/settings.log"
filePattern="${basePath}/settings-%d{yyyy-MM-dd}.log">
<PatternLayout
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
<SizeBasedTriggeringPolicy size="250000000" />
</RollingFile>
<Console name="AgileAppsConsoleAppender" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Logger name="com.agileapps.settings" level="trace">
<AppenderRef ref="AgileAppsFileAppender" />
</Logger>
<Root level="warn">
<AppenderRef ref="AgileAppsConsoleAppender" />
</Root>
</Loggers>
</Configuration>

关于java - RestAssured 外部文件日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57717589/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com