I want to add a magazine view tab to my site. The tab should print the entire log file, and after that print only new lines (for example, a tail -Fcommand in Linux). The client side is in HTML and Javascript, and the server side is in Python.
Here is my Python function of my tail (I found it on the Internet):
@cherrypy.expose
def tail(self):
filename = '/opt/abc/logs/myLogFile.log'
f = subprocess.Popen(['tail','-F',filename],\
stdout=subprocess.PIPE,stderr=subprocess.PIPE)
p = select.poll()
p.register(f.stdout)
while True:
if p.poll(1):
print f.stdout.readline()
time.sleep(1)
This code does print the entire log file. However, every time I add new lines to a file, the file is printed from the very beginning, instead of printing new lines.
Any suggestions for fixing it? I am new to Python, so I would appreciate any help.
source
share