ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruce Atherton <>
Subject Re: live view of the file contents
Date Wed, 04 Jan 2012 22:09:50 GMT
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:

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):,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

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message