As part of a process to check and report on errors I pass into a target a file to
${file}. I then process the file looking for a given regular expression ${string}. If
there is a "hit" on this then I generate an e-mail message stating that an error was
found in the log and send the log file. What I would like to do is send a subset of
the log which contains 2 lines above and 2 lines below the error message found. The
<switch> function is used because some of the log files I am searching have a "was
good" message I can search for because some of the procedures have words like Fail and
Error :)
I'm guessing I have to add something to the <loadfile> section that does the lines
above and below so that the property message.log contains the information in it. If I
could get that then I could just mail ${message.log} instead of ${file}
<target name="CheckFile">
<echo message="Checking File=${file}"/>
<echo message="For string ${string}"/>
<echo> In CheckFile2 for error </echo>
<loadfile property="message.log" srcFile="${file}">
<filterchain>
<filterreader
classname="org.apache.tools.ant.filters.LineContainsRegExp">
<param type="regexp" value="${string}*"/>
</filterreader>
</filterchain>
</loadfile>
<switch value="${CheckType}">
<case value="Success">
<condition property="has.error" value="did not">
<not>
<contains string="${message.log}"
substring="${string}"/>
</not>
</condition>
<echo></echo>
</case>
<default> <!-- the default is Check for Failure -->
<condition property="has.error" value="did">
<contains string="${message.log}"
substring="${string}"/>
</condition>
</default>
</switch>
<antcall target="mail-if-error">
<param name="file" value="${file}"/>
<param name="string" value="${string}"/>
</antcall>
</target>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]