Export http log to a file with groovy script

soapUI pro announcements and discussions

Export http log to a file with groovy script

Postby rdebie » 27 Jun 2007 13:24

Hello,

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

regards,

Raymond Wiertz
rdebie
soapui pro users
soapui pro users
 
Posts: 49
Joined: 11 May 2007 11:31

Re: Export http log to a file with groovy script

Postby omatzura » 27 Jun 2007 14:22

Hi!

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

Code: Select all
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:

Code: Select all
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
omatzura
Administrator
Administrator
 
Posts: 1918
Joined: 05 Jan 2007 23:39

Re: Export http log to a file with groovy script

Postby rdebie » 27 Jun 2007 14:25

Oke,

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

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

does this works also?

Raymond Wiertz
rdebie
soapui pro users
soapui pro users
 
Posts: 49
Joined: 11 May 2007 11:31

Re: Export http log to a file with groovy script

Postby omatzura » 27 Jun 2007 15:02

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;

Code: Select all
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

Code: Select all
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
omatzura
Administrator
Administrator
 
Posts: 1918
Joined: 05 Jan 2007 23:39

Re: Export http log to a file with groovy script

Postby rdebie » 27 Jun 2007 15:15

Oke,

Tanks for your support.

regards,

Raymond.


This is really a great functionality    :)
Last edited by rdebie on 27 Jun 2007 15:19, edited 1 time in total.
rdebie
soapui pro users
soapui pro users
 
Posts: 49
Joined: 11 May 2007 11:31

Re: Export http log to a file with groovy script

Postby nreimertz » 29 Jun 2007 09:40

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
nreimertz
Administrator
Administrator
 
Posts: 441
Joined: 05 Jan 2007 23:39


Return to soapUI Pro Support