I have to read data from log files present in realtime. I used the code mentioned in Reading multiple files in real time? however I am able to read only the first file i.e system.log. How to read all the files iteratively i.e first system.log and then wifi.log and repeat the same process again.
import time
import glob
import threading
def follow(thefile):
thefile.seek(0,2)
while True:
line = thefile.readline()
if not line:
time.sleep(0.1)
continue
yield line
lock = threading.Lock()
def printFile(logfile):
loglines = follow(logfile)
for line in loglines:
lock.acquire()
print (line)
lock.release()
if __name__ == '__main__':
files=['system.log','wifi.log']
for log in files:
logfile = open(log, "r")
t = threading.Thread(target = printFile,args = (logfile,))
t.start()