Im a Python newbie so forgive any shortcomings.
Im using a Python script to watch a folder that has cycled logs. When one of the logs contains a line the word "Alert:" , I want to write data from that line out to text file Output.txt.
Log Sample ( of files that reside in the directory im watching ) looks like:
Normal:Action='Push',Id='1434456544527',Other='BBB'
Normal:Action='Push',Id='1434456544527',Other='BBB'
Normal:Action='Push',Id='1434456544527',Other='BBB'
Normal:Action='Push',Id='1434456544527',Other='BBB'
Alert:Action='Pull',Id='1434456544527',Other='AAA'
Normal:Action='Push',Id='1434456544527',Other='BBB'
So I would like to have Output.txt contain:
Pull,1434456544527,AAA
This is my script - the trackit is from http://code.activestate.com/recipes/577968-log-watcher-tail-f-log/
from trackit import *
import os
import re
import sys
import subprocess
text_file = open("Output.txt", "w")
def callback(filename, lines):
for line in lines:
if 'Alert' in str(line):
#print str(line)
text=str(line)
cities = text.split("'")
matches = re.findall(r"[\w']+", text)
print(matches)
####text_file.write( 'dict = ' + matches + '\n' )
else:
color=1
watcher = LogWatcher("/folder/logs", callback)
watcher.loop()
text_file.close()
The piece I need assistance with is how to split out the line when variables are defined as variable='Value' ?
Thanks in advance