larry.bates at websafe.com
Tue Jan 16 01:33:13 CET 2007
Salvatore Di Fazio wrote:
> Hi guys,
> I've an application that writes a log file.
> I need to write an application with python that will read this file.
> I would like wait until a new line will be write in the file.
> Something like the "watch cat Log" command on Linux os.
> How can I check the eof and restart the reading?
You didn't provide much info so here goes. If you use the
logger module built into Python you can set up a logger that
uses sockets. Have your program log to a socket and have the
other program read from the socket. That way you will always
have the latest log entries in the monitor program.
If you can't control the program that writes the log file,
have your monitoring program look for change in the length
of the logfile (you can use the os.stat module for this).
When it changes, open the file, seek to the old length and
read bytes up to the new length and close the logfile.
What is read will be the new log entry (or entries).
Reset the logfile length high water mark and loop.
Hope information helps.
More information about the Python-list