Forum Discussion
nmrao
10 years agoCommunity Hero
Please see this link http://stackoverflow.com/questions/28610193/logging-using-log4j-in-soapui
davidp_1
10 years agoOccasional Contributor
Hi -- Yes, I'd seen that post, and that's where I learned about setting up the custom logger. What I was missing was pretty simple -- how to get groovy assert results into that file. I needed to put the assert into a try/catch, like this:
import org.apache.log4j.Logger
def fileLogger = Logger.getLogger("ASSERTION.SCRIPT.LOGGER");
def String expected = "Some Text"
def String actual = "Some Unexpected Text"
assertVals(actual, expected, fileLogger)
def assertVals(String actual, String expected, Logger logger) {
if (expected != null) {
try {
assert expected == actual
}
catch(AssertionError e) {
logger.info(e.getMessage())
}
}
}Two notes:
- If you want the "power assert" formatting in the file, leave it as above. If you want a more standard version on a single line, add the optional ": 'This is the result'" part after the assert statement. Not sure why that is, but it works.
- Because the "power assert formatting is sensitive, I turned off the formatting in the layout of the appender.
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n"/>
</layout>Of course, when you do that you don't get useful stuff like date/time.
Thanks,