Skip to content

Instantly share code, notes, and snippets.

@kurtiss
Created February 12, 2011 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurtiss/823569 to your computer and use it in GitHub Desktop.
Save kurtiss/823569 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import glob
import time
files = set()
positions = dict()
def _add_new_files(read = True):
global files
all_files = set(glob.glob("*.log"))
new_files = all_files - files
files = all_files
for file in new_files:
handle = open(file, "r")
if read:
handle.read()
positions[file] = handle.tell()
_add_new_files()
while True:
time.sleep(.1)
_add_new_files(False)
for file, pos in positions.iteritems():
file_written = False
with open(file, "r") as handle:
handle.seek(pos)
while True:
line = handle.readline()
if line:
if file_written:
print "====== {0}".format(file)
print line
else:
break
positions[file] = handle.tell()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment