The context is:
- I want to start my application
- I need to automatically analyze the log file "myLog.out". More exactly: if a string like "System started" is inserted at the end of the file.
- Not only "System started" is written in "myLog.out"; there are other information logged.
- If "System started" was written by the application i see a "Test passed!!!" message as output; otherwise i read a sadly "Test failed!!!" message
The solution is built using:
- The Grep Task written by Tigris (download available here)
- The FTP Task with a get action
- The Loadfile Task with a filter (FilterChain) because only the last X lines of the log are important
- The Condition Task to print the right output message:
<project name="someProject" default="default">
<taskdef name="grep" classname="ise.antelope.tasks.Find"/>
<target name="default">
<ftp server="aServer" port="aPort" remotedir="/log"
userid="aUser" password="aPassword" binary="no" action="get">
<fileset file="myLog.out"/>
</ftp>
<loadfile property="logcontent" srcFile="myLog.out">
<filterchain>
<tailfilter lines="4"/>
</filterchain>
</loadfile>
<grep in="${logcontent}" regex=".*System started.*" property="output"/>
<condition property="test-passed">
<isset property="output"/>
</condition>
<condition property="test-failed">
<not>
<isset property="output"/>
</not>
</condition>
<antcall target="print-1"/>
<antcall target="print-2"/>
</target>
<target name="print-1" if="test-passed">
<echo>Test passed!!!</echo>
</target>
<target name="print-2" if="test-failed">
<echo>Test failed!!!</echo>
</target>
</project>
Nessun commento:
Posta un commento