ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mario Manfre" <>
Subject Search log file and get rows above and below search "hits"
Date Fri, 12 Mar 2004 15:24:32 GMT

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}">
				<filterreader classname="">
					<param type="regexp" value="${string}*"/>
		<switch value="${CheckType}">
			<case value="Success">
				<condition property="has.error" value="did not">
						<contains string="${message.log}" substring="${string}"/>
			<default> <!-- the default is Check for Failure -->
				<condition property="has.error" value="did">
					<contains string="${message.log}" substring="${string}"/>
		<antcall target="mail-if-error">
			<param name="file" value="${file}"/>
			<param name="string" value="${string}"/>

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message