Logging 在SoapUI中使用log4j进行日志记录
在过去的几个小时里,我尝试在我的SoapUI项目中使用log4j配置和使用一个自定义记录器。一般来说,我的日志工作没有任何问题,但我假设log4j有一些很好的特性,这将很好地使用 当前的方法如下所示:Logging 在SoapUI中使用log4j进行日志记录,logging,groovy,log4j,soapui,Logging,Groovy,Log4j,Soapui,在过去的几个小时里,我尝试在我的SoapUI项目中使用log4j配置和使用一个自定义记录器。一般来说,我的日志工作没有任何问题,但我假设log4j有一些很好的特性,这将很好地使用 当前的方法如下所示: File file = new File("C:\\Users\\doms\\Desktop\\log.txt") file << ("-------" + "Check httpStatus and ResponseTime" + "-------") file << (
File file = new File("C:\\Users\\doms\\Desktop\\log.txt")
file << ("-------" + "Check httpStatus and ResponseTime" + "-------")
file << ("\r\n")
//httpStatus
httpResponseHeader = messageExchange.responseHeaders
httpStatus = httpResponseHeader['#status#']
httpStatusCode = (httpStatus =~ "[1-5]\\d\\d")[0]
log.info("httpStatus of Request: " + httpStatusCode)
file << ("httpStatus of Request: " + httpStatusCode )
file << ("\r\n")
//ResponseTime
responseTime = messageExchange.getTimeTaken()
log.info("ResponseTime: " + responseTime + "ms.")
file << ("ResponseTime: " + responseTime + "ms.")
file << ("\r\n")
否我已经创建了一个新的GroovyScript作为测试用例,其内容如下:
import org.apache.log4j.Logger
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
// ASSERTION.SCRIPT.LOGGER is defined in soapui-log4j.xml as below
def fileLogger = Logger.getLogger("ASSERTION.SCRIPT.LOGGER");
log.info(fileLogger.class.name)
responseTime = testRunner.testCase.testSteps["myTestStep"].testRequest.response.timeTaken
// > 1 to get sure that I'll get in the if-statement.
if (responseTime > 1) {
//get sure that script goes into the if-clause by printing a line in SoapUIs's console
log.info("ResponseTime is: " + responseTime)
fileLogger.info ("FAULT: Response took:" + responseTime)
}
结果是调用了log.info(“ResponseTime是:”+ResponseTime)
,但不会将任何内容记录到任何文件中。此外,我通过
定义的文件将不会被创建(不在SoapUI的bin目录中,也不在项目目录中)
我错过什么了吗?非常感谢任何tipp 我认为你做的事情是正确的,请注意以下几点: 如果直接为参数
指定一个值,则日志将在SOAPUI\u HOME\bin\
目录中创建该文件。请注意,您可以像这样声明完整路径:
如果在fileLogger
对象中加载记录器配置,则可以使用类似fileLogger.info(“故障:响应时间:“+responseTime”)
的对象写入日志文件,而不使用log.info
。我这样说是因为在你的问题中你说:
结果是log.info(“ResponseTime是:“+ResponseTime”)得到
调用,但不会将任何内容记录到任何文件中
总结:我认为您的所有配置都是正确的,因此我建议您简化groovy脚本,如下所示,以确保日志正常工作,而不是让日志出错的原因:
import org.apache.log4j.Logger
def fileLogger = Logger.getLogger("ASSERTION.SCRIPT.LOGGER");
fileLogger.info("testing log");
希望这有帮助,Hey@albciff!我终于让它工作了。原因不知何故是由于我在工作计算机上的用户权限受到了限制,也可能是因为我的配置文件被弄乱了。不管怎样:它正在工作!:)谢谢你的帮助和努力@很高兴现在它能工作了。谢谢你
:)
import org.apache.log4j.Logger
def fileLogger = Logger.getLogger("ASSERTION.SCRIPT.LOGGER");
fileLogger.info("testing log");