Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Logging 在SoapUI中使用log4j进行日志记录_Logging_Groovy_Log4j_Soapui - Fatal编程技术网

Logging 在SoapUI中使用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 << (

在过去的几个小时里,我尝试在我的SoapUI项目中使用log4j配置和使用一个自定义记录器。一般来说,我的日志工作没有任何问题,但我假设log4j有一些很好的特性,这将很好地使用

当前的方法如下所示:

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");