On 04/01/2012 10:16 AM, Raja Nagendra Kumar wrote:
intent is to automate the viewing of the Server Logs after the server
is started through ant script..
I can write a ant task which opens the file and prints to the console...
as suggested by you, usage of exec would any way makes the ant script
less portable..for one more time.. we want to minimize exec usage as
far as possible and invent pure java ways..
Well, you could write a "follow" Ant task. It wouldn't be hard,
particularly if you used the Apache Commons Tailer class:
http://commons.apache.org/io/api-release/org/apache/commons/io/input/Tailer.html
Or you could use a <script> tag and write something like this with the
appropriate setup of Ant and BSF. Note that this is untested, and it
doesn't deal with log file rollover/truncation the way that the Tailer
class will:
| <property name="logfilename" value="request.log" />
<script language="jython">
import time
def follow(logfile):
logfile.seek(0,2) # Optional: Seek end of file
while True:
line= logfile.readline()
if line:
|| yield line
|| continue
|| time.sleep(0.5) # Sleep for a bit
currfile= open(logfilename)
loglines= follow(currfile)
for linein loglines:
print line
</script>
|