I'm trying to listen log files that are constantly updated and work with the lines continuously. The thing is that I have multiple files to listen. The logs are separated by the jboss instances and I have to work with all them together to insert them on a database.
I've got a good example of how to read a file continuously from the question 5419888, but this code only reads one file by time. I've tried the following code to read them all, but it only listen to the first file it finds in the array of files.
How could I multithread this to process all the files at the same time?
import time
from glob import glob
def follow(thefile):
thefile.seek(0,2)
while True:
line = thefile.readline()
if not line:
time.sleep(0.1)
continue
yield line
if __name__ == '__main__':
for log in glob("/logs/xxx/production/jboss/yyy*/xxx-production-zzzz*/xxx-production-zzzz*-xxx-Metrics.log"):
logfile = open(log, "r")
loglines = follow(logfile)
for line in loglines:
print line,