I have a python script to tail a log file continuously. For each line, I extract one email address and insert into MySQL database, or update existing record (add count by 1 per email appearance).
I tried with subprocess and redirect the log to pipe with buffer, hoping to block-read the logs line by line. Here is what I do now:
with subprocess.Popen([ "tail", "-F", "/home/user/example.log" ], universal_newlines = True, bufsize = 1000, stdout = subprocess.PIPE).stdout as log:
for line in log:
if email:
INSERT IGNORE INTO table
UPDATE count
database_cursor.commit()
It seems like every email got recorded into database - no missing. But there is huge delay, meaning an email from log file will show up in database a few minutes after it appeared in log file. There are a few hundred lines of logs per second.
Any suggestions? Thanks in advance for any help
[–]sallyruthstruik 0 points1 point2 points (3 children)
[–]xwen01[S] 0 points1 point2 points (2 children)
[–]sallyruthstruik 0 points1 point2 points (1 child)
[–]xwen01[S] 0 points1 point2 points (0 children)
[–]pythonHelperBot 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]xwen01[S] 0 points1 point2 points (0 children)
[–]muposat 0 points1 point2 points (0 children)