Created
February 12, 2011 07:01
-
-
Save kurtiss/823569 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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