title: Logging using log4j in SoapUI
body: <p>For the last hours I've tried to configure and use a custom logger using log4j in my SoapUI project. Generally my logging works without any problems, but I assume that log4j has some nice features, which would be nice to use.</p>
  
  <p>Current approach looks like the following:</p>
  
  <pre><code>File file = new File("C:\\Users\\doms\\Desktop\\log.txt")
  file &lt;&lt; ("-------" + "Check httpStatus and ResponseTime" + "-------")
  file &lt;&lt; ("\r\n")
  
  //httpStatus
  httpResponseHeader = messageExchange.responseHeaders
  httpStatus = httpResponseHeader['#status#']
  httpStatusCode = (httpStatus =~ "[1-5]\\d\\d")[0]
  log.info("httpStatus of Request: " + httpStatusCode)
  file &lt;&lt; ("httpStatus of Request: " + httpStatusCode )
  file &lt;&lt; ("\r\n")    
  
  //ResponseTime
  responseTime = messageExchange.getTimeTaken()
  log.info("ResponseTime: " + responseTime + "ms.")
  file &lt;&lt; ("ResponseTime: " + responseTime + "ms.")
  file &lt;&lt; ("\r\n")
  </code></pre>
  
  <p>This results in an output of:</p>
  
  <blockquote>
    <p>-------Check httpStatus and ResponseTime-------<br>
    httpStatus of Request: 200<br>
    ResponseTime: 767ms.</p>
  </blockquote>
  
  <p>Assumed the file gets bigger and biger and get thousands lines of text, I want to have an automatic process, where a new file will be created, if the file-size is bigger than 10MB. The new file should called <strong>log-1.txt</strong>. From my understanding, log4j is the perfect solution for my purpose.
  I've already searched for some instructions and found this: <a href="http://0guzhan.blogspot.de/2011/12/defining-custom-loggers-in-soapui.html" rel="nofollow">http://0guzhan.blogspot.de/2011/12/defining-custom-loggers-in-soapui.html</a></p>
  
  <p>So...what I have done: I've edited the <code>soapui-log4j.xml</code> and I've added the following lines:</p>
  
  <pre><code>&lt;logger name="ASSERTION.SCRIPT.LOGGER"&gt;
        &lt;level value="INFO"/&gt;
        &lt;appender-ref ref="ASSERTION"/&gt;
  &lt;/logger&gt;
  
  &lt;appender name="ASSERTION" class="org.apache.log4j.RollingFileAppender"&gt;
       &lt;errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler"/&gt;
       &lt;param name="File" value="ASSERTION.log"/&gt;
       &lt;param name="Threshold" value="INFO"/&gt;
       &lt;param name="Append" value="false"/&gt;
       &lt;param name="MaxFileSize" value="10000KB"/&gt;
       &lt;param name="MaxBackupIndex" value="50"/&gt;
       &lt;layout class="org.apache.log4j.PatternLayout"&gt;
           &lt;param name="ConversionPattern" value="%d %-5p [%c{1}] %m%n"/&gt;
       &lt;/layout&gt;     
  &lt;/appender&gt;
  </code></pre>
  
  <p>No I have created a new GroovyScript as a Testcase with the follwoing content:</p>
  
  <pre><code>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
  // &gt; 1 to get sure that I'll get in the if-statement.
  if (responseTime &gt; 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)
  }
  </code></pre>
  
  <p>The result is that <code>log.info("ResponseTime is: " + responseTime)</code> get called, but nothing will be logged to any file. Also the file, which I've defined via <code>&lt;param name="File" value="ASSERTION.log"/&gt;</code> won't be created (not in SoapUI's bin-directory, not in the project-directory).</p>
  
  <p>Do I miss anything? Any tipp is much appreciated!</p>