Forum Discussion
nmrao
9 years agoChampion Level 3
Please see this link http://stackoverflow.com/questions/28610193/logging-using-log4j-in-soapui
- davidp_19 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,
- nmrao9 years agoChampion Level 3
If you are looking for date and all you need provide the appropriate value in the configuration for ConversionPattern.
You may try something like below
%d{dd-MMM-yyyy HH:mm:ss,SSS} [%-8t] %-5p %c{1}:%L %x - %m %n
- davidp_19 years agoOccasional Contributor
The reason I mention it is because if you include the date, and you elect to go with the groovy power assert formatting, it won't look right (those lines won't line up correctly).
Instead of this:
assert expected == actual | | | Some Text| Some Unexpected Text false
You'll get this:
2015-12-01 23:05:26,655 INFO [LOGGER] assert expected == actual | | | Some Text| Some Unexpected Text false
Related Content
Recent Discussions
- 20 hours agogroovyguy