Forum Discussion

khapre's avatar
khapre
Occasional Contributor
12 years ago

How to read Request log from groovy

Hi,

could any body tel me how to read the request log area from groovy script ?

thanks in advance.

Ashish

4 Replies

  • tjdurden's avatar
    tjdurden
    Frequent Contributor
    Hi Ashish,

    Are you looking for any specific data from the log, or do you just want the entire output? For example, the response time can be gathered by:

    log.info("Response Time :" + messageExchange.getTimeTaken())


    I've been having a look at the SoapUI API's and I'm not sure how to specifically grab the Response Log from a SOAP request directly using Groovy. It may be easier to consider what you are trying to achieve by grabbing the logs unless anyone else knows specifically?

    Kind regards,
    Tim
  • tjdurden's avatar
    tjdurden
    Frequent Contributor
    Furthermore, whilst this doesn't answer your question, in the process of trying to find an answer, I did find a way to access other logs (via Groovy) within SoapUI, as follows:


    // Can be altered to 'soapUI log', 'http log', 'jetty log', 'error log' etc.
    def logArea = com.eviware.soapui.SoapUI.logMonitor.getLogArea( "http log" );

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    if( logArea !=null )
    {
    def model = logArea.model
    // only continue of logArea not empty
    if( model.size > 0 )
    for( c in 0..(model.size-1) )

    // DO SOMETHING HERE... could write to file, could run assertions, etc.
    log.info(model.getElementAt(c))
    }

    Kind regards,
    Tim
  • khapre's avatar
    khapre
    Occasional Contributor
    Thanks Tim for your reply.
    Yes, my main purpose as of now is to get the response time for analysis.

    your suggestion 1:

    log.info("Response Time :" + messageExchange.getTimeTaken())

    Some how this is not working for me even though I am using
     import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStepResult; 



    suggestion 2:

    Yes you are right, this is the way we can access logArea, but again it doesn't work on "Request log" where as it works fine for "soapui log" "http log" ...... etc I mean all the bottom log tab. It seems that "request log" is not defined under logArea or SOAPUI log monitor

    Though, I can read the response time from "soapui log" but it has so many other information as well, that it takes quite an effort to extract the response time.

    If I can get where "Request log" is defined or how to get this log area, then it will simplify my task. If its seen on the UI then it must be defined somewhere.
    I just need this forums help to find out


    Thanks again.
    Ashish
  • ankyeez's avatar
    ankyeez
    Occasional Contributor
    Hi Ashish,

    I can give you an advice. Before running the request you can empty the log using this :

    def logArea = com.eviware.soapui.SoapUI.logMonitor.getLogArea( "http log" );
    If(logArea != null){
    //setting http logArea as empty
    logArea = null
    }

    Then after running the request use TIM's code.

    Thanks,
    ankyeez