You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Raja Nagendra Kumar <na...@tejasoft.com> on 2012/01/04 10:33:20 UTC

live view of the file contents

Hi,

I am starting tomcat using exec task with spawn to be true... I am also
redirecting all the tomcat logs to a file.


If we like to open the log file after tomcat starting.. what is the best way
to see the content coming in dos console... as and when some thing is
written to log file..

Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com

--
View this message in context: http://ant.1045680.n5.nabble.com/live-view-of-the-file-contents-tp5119163p5119163.html
Sent from the Ant - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: live view of the file contents

Posted by Bruce Atherton <br...@callenish.com>.
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>
|



Re: live view of the file contents

Posted by Raja Nagendra Kumar <na...@tejasoft.com>.
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..

It may be good for ant to think of some task like tail etc..

Thank you for your inputs and looking forward to more thoughts..

Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com
On 1/4/2012 10:02 PM, Bruce Atherton wrote:
> On 04/01/2012 1:33 AM, Raja Nagendra Kumar wrote:
>> If we like to open the log file after tomcat starting.. what is the 
>> best way
>> to see the content coming in dos console... as and when some thing is
>> written to log file..
>>
>
> I don't think there is a way to do this strictly with Ant tasks (I 
> would have expected it in the concat task or the tail filter), but 
> from the command line of a Unix system you use:
>
>     tail -f file.log
>
> If you wanted Ant to do that for some reason, you could stick that 
> command in an exec task or use a script to accomplish the same thing. 
> It is a bad idea, though, because it leaves Ant running forever just 
> to watch a log file, and the combination of Java and Ant is quite 
> large. You are better off running the "tail -f" command by itself, 
> from outside of Ant. Perhaps started in a batch file that has 
> previously run Ant.
>
> For Windows, you could install cygwin to get the same program. Or 
> google for other tail programs that have the follow feature.
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: live view of the file contents

Posted by Bruce Atherton <br...@callenish.com>.
On 04/01/2012 1:33 AM, Raja Nagendra Kumar wrote:
> If we like to open the log file after tomcat starting.. what is the best way
> to see the content coming in dos console... as and when some thing is
> written to log file..
>

I don't think there is a way to do this strictly with Ant tasks (I would 
have expected it in the concat task or the tail filter), but from the 
command line of a Unix system you use:

     tail -f file.log

If you wanted Ant to do that for some reason, you could stick that 
command in an exec task or use a script to accomplish the same thing. It 
is a bad idea, though, because it leaves Ant running forever just to 
watch a log file, and the combination of Java and Ant is quite large. 
You are better off running the "tail -f" command by itself, from outside 
of Ant. Perhaps started in a batch file that has previously run Ant.

For Windows, you could install cygwin to get the same program. Or google 
for other tail programs that have the follow feature.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org