473,386 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Watch log

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?

Jan 15 '07 #1
7 2552
Salvatore Di Fazio wrote:
I would like wait until a new line will be write in the file.

Something like the "watch cat Log" command on Linux os.
Why not read the file continuously and only do something if a new
line is complete (i. e. a newline char is detected)?
How can I check the eof and restart the reading?
Why do you want to check for an EOF character?

Regards,
Björn

--
BOFH excuse #212:

Of course it doesn't work. We've performed a software upgrade.

Jan 15 '07 #2
Bjoern Schliessmann ha scritto:
Why not read the file continuously and only do something if a new
line is complete (i. e. a newline char is detected)?
How can I read the file continuously?

Jan 15 '07 #3
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.

-Larry Bates
Jan 16 '07 #4
Salvatore Di Fazio wrote:
Bjoern Schliessmann ha scritto:

>Why not read the file continuously and only do something if a new
line is complete (i. e. a newline char is detected)?

How can I read the file continuously?

What you want is something like 'tail -f' in linux.
If you look into it's source code, you will find it check file periodically.
When a read() reach the end of the file, read() will return a empty string.
You can try to read data from the file periodically after a EOF.
I think it is what you want.

--
Thinker Li - th*****@branda.to th********@gmail.com
http://heaven.branda.to/~thinker/GinGin_CGI.py

Jan 16 '07 #5
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.
You may begin from this:

$ cat showlog.py
import sys
from ScrolledText import ScrolledText

interval =50 # ms

def displayfile(f, textwidget):
textwidget.insert('end', f.readline())
textwidget.after(interval, displayfile, f, textwidget)

if __name__ == '__main__':
st = ScrolledText()
st.pack()
displayfile(sys.stdin, st)
st.mainloop()

$ python showlog.py < mylogfile.log

HTH,
Michele Simionato

Jan 16 '07 #6
Thinker ha scritto:
What you want is something like 'tail -f' in linux.
If you look into it's source code, you will find it check file periodically.
When a read() reach the end of the file, read() will return a empty string.
You can try to read data from the file periodically after a EOF.
I think it is what you want.
So every 2 sec:
- open the file
- read the file from the oldPosition to the EOF
- save the last position in file
- first point

mmm ok

Jan 16 '07 #7
Michele Simionato ha scritto:
You may begin from this:
Tnx Michele

Jan 16 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Premshree Pillai | last post by:
Hello, I recently posted a simple Python script--Watch That Post--that lets you watch a URL for any changes. I wrote it to watch posts on LiveJournal, but it can watch any URL. It's at...
3
by: jason | last post by:
Does anyone have any ideas on a PAGE WATCH tool or an application that allows a user to be notified when page changes automatically by email. My immediate thoughts would be to use the FSO object...
3
by: Neil | last post by:
Hi, If I have the code line "DateTime d1 = DateTime.Now;" and look at d1 in the watch window, I thought I'd only see the properties of the DateTime object variable d1. However I seem to be...
2
by: Peter Steele | last post by:
Say I have a managed C++ app with some code that looks something like this: void MyMethod() { struct Point { int x, y; }; Point* p = new Point; p.x = 1; p.y = 2;
7
by: Brad | last post by:
When debugging my current web project, in VS2003, I found I had lost the ability to drill down on watch objects in the Watch Window; I could only view the single value specific watch objects. ...
2
by: Enrique Bustamante | last post by:
Casting arrays that works on watch and command window but not in code. My application is casting arrays in a way it should work. To test if I was doing something invalid, I wrote a test code that...
6
by: Tau | last post by:
look my simple code below(vc8): double ends; ends=8.3; when i debug it, the variable ends cannot be displayed in the watch window. it just said "error: index '0' out of bound for...
8
by: Greg | last post by:
Dear all, I've trouble with debugging a huge programm. I want to look into the properties of an object when I am at a breakpoint. But in the watch window he tell's me that the object is "out of...
15
geolemon
by: geolemon | last post by:
I'm having a seriously Twilight Zone moment: In the code below, I'm building a SQL command into a string variable, declared at the top of my code. Then, I connect to the database and try to...
176
by: . | last post by:
9/11 Mysteries http://video.google.com/videoplay?docid=-8172271955308136871 http://www.911weknow.com Ignore those who would go to great effort and expend much of heir time in poo-pooing this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.