Forum Discussion

Joey_Seekata's avatar
Joey_Seekata
New Contributor
17 years ago

Log4j and extending the HtmlLayout layout class

I think this is really about hooking in java code in general, but my specific need is to extend HTMLLayout (org.apache.log4j.HTMLLayout).  In the version of log4j that comes with SOAPui, the output from HTMLLayout is fixed (HTMLLayout does not derive from PatternLayout and therefore does not accept an ConversionPattern).

If I were to extend HTMLLayout in java, can I hook that code into SOAPui?  For example, I currently have this in soapui-log4j.xml:

 
   
   
     

 


What I would like to do is (for example):

 
   
   
     

 


Where would I put the jar file that contains com.company.project.MyHtmlLayout such that SOAPui will load it up at startup?

Thanks for your attention to this matter.

Joey

4 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Joey,

    normally you would be able to drop the jar-file into the \bin\ext folder, but since the log4j configuration is read before this folder is processed, you will need to manually add your jar to the classpath in soapui.bat.. unless log4j doesn't actually instantiate your layout until after the bin\ext folder has been processed (which is just after the log4j.xml file has been read), in which case you should be able to just put your jar in the bin\ext folder..

    Hope this helps!

    regards!

    /Ole
    eviware.com
  • Omatzura,

    Thanks so much.  Turns out log4j is processed first so the soapui-pro.bat file needed to be modified. 

    Next task, resetting the log file when a test case is run.  log4j's FileAppender has a property "Append" and it is set to false.  So when SoapUI-Pro starts up, the old log file is cleared (emptied of data).  That is great, but what I am being asked to do requires that same emptying for each test case run.  Any thoughts?  I have, of course, poured over the log4j documents and do not see anything that looks promising, so I am asking here.

    Thanks again,

    Joey
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Joey,

    maybe you can create a groovy-script first in your testcase that gets the loggers' FileAppender and calls its activateOptions method? ie

    Logger.getLogger(..).getAppender( .. ).activateOptions()

    which should reset the log (if I understand the javadocs correctly)!?

    Hope this helps!

    regards,

    /Ole
    eviware.com
  • Omatzura,

    I don't know how you got that from the javadocs, but it was brilliant.  I used:

    Logger.getRootLogger().getAppender("testResults").activateOptions();

    and sure enough, it closed and reopened it.  With append set to false, it reopened it "clean".

    I could not figure out what name to put into the Logger.getLogger call, so I used getRootLogger instead.

    Who said there are no pointers in java?  You pointed me in the right direction with some java code.

    But still, how did you get that behavior from the javadocs?  Some kind of secret decoder ring or what?

    Thanks so much!

    Joey