cancel
Showing results for 
Search instead for 
Did you mean: 

Export http log to a file with groovy script

Contributor

Export http log to a file with groovy script

Hello,

Can i export the log window 'http log' to a file.
I want to do this with a groovy script.

regards,

Raymond Wiertz
5 REPLIES 5
Super Contributor

Re: Export http log to a file with groovy script

Hi!

sure.. you can loop the elements in the model we accessed in the previous script and write them to a file:

def logArea = com.eviware.soapui.SoapUI.logMonitor
if( logArea != null )
{
  def ix = logArea.indexOfTab( "http log" );
  if( ix >= 0 )
  {
      def logPanel = logArea.getComponentAt( ix )
      def model = logPanel.logList.model
      if( model.size > 0 )
      {
        def out = new java.io.PrintWriter( "myfile.log" )
   
        for( c in 0..(model.size-1) )
            out.println( model.getElementAt( c ))

        out.close()
      }
  }
}


if you want to make it really fancy you can prompt for the file:


def logArea = com.eviware.soapui.SoapUI.logMonitor
if( logArea != null )
{
  def ix = logArea.indexOfTab( "http log" );
  if( ix >= 0 )
  {
      def logPanel = logArea.getComponentAt( ix )
      def model = logPanel.logList.model
      if( model.size > 0 )
      {
        def file = com.eviware.soapui.support.UISupport.fileDialogs.saveAs(
            null, "Export Log", "*.log", "*.log", null )
        if( file != null )
{
            def out = new java.io.PrintWriter( file )
   
            for( c in 0..(model.size-1) )
              out.println( model.getElementAt( c ))

            out.close()
        }
      }
  }
}


regards!

/Ole
Contributor

Re: Export http log to a file with groovy script

Oke,

great , can i do this also for the Test log?

def ix = logArea.indexOfTab( "test log" );

does this works also?

Raymond Wiertz
Super Contributor

Re: Export http log to a file with groovy script

Hi,

if you mean the log in the groovy-editor window, the answer is no.. there is no way to currently access that log.. but all the other logs at the bottom are available.. actually, you can even add your own from a script;

def logArea = com.eviware.soapui.SoapUI.logMonitor
if( logArea != null )
{
  def ix = logArea.indexOfTab( "my log" );
  def logPanel

  if( ix == -1 )
  {
      logPanel = logArea.addLogArea( "My log", "my.log.category", false )
  }
  else
  {
      logPanel = logArea.getComponentAt( ix )
  }

  logPanel.addLine( "test" )
}


Then in subsequent teststeps/testcases you can log to this with

def mylog = org.apache.log4j.Logger.getLogger( "my.log.category" )
mylog.info( "testing.." )


Since this is standard log4j stuff, you could add an SNMP appender for monitoring, JDBC appender for logging to database, etc..

regards!

/Ole
eviware.com
Contributor

Re: Export http log to a file with groovy script

Oke,

Tanks for your support.

regards,

Raymond.


This is really a great functionality   

Re: Export http log to a file with groovy script

We will be writing a tutorial in the upcoming weeks for what Ole described. Using the SMTPappender (sending mail when a test fails) or NTEventLogappender (Writing to the Windows Event Viewer to be handled by Service Management Software) is really useful.

/niclas
Product Guy for Ready! API, SoapUI and all things API
New Here?
Join us and watch the welcome video:
Top Kudoed Authors