I want to select executed query from log file. Specifically an example would look something like this:
2019-01-10 10:33:21 +07 dvdrentalLOG: statement: SELECT last_update
From public.actor
2019-03-06 14:07:06 +07 dvdrentalLOG: statement: SELECT film_id, title
FROM public.film
WHERE film_id = 1
I want to get the queries using looping. desired output:
query1 : SELECT last_update From public.actor
query2 : SELECT film_id, title FROM public.film WHERE film_id = 1
This I have tried:
import re
def parseFile(filepath):
line=[]
with open(filepath,'r') as log:
regex = re.compile(r'(\d{4}-\d{2}-\d{2})(.*)',re.MULTILINE|re.DOTALL)
for line in log:
date = regex.findall(line)
if date == []:
print()
else:
print(date)
filepath = 'text.txt'
parseFile(filepath)
output:
[('2019-01-10', ' 10:33:21 +07 dvdrentalLOG: statement: SELECT last_update \n')]
[('2019-03-06', ' 14:07:06 +07 dvdrentalLOG: statement: SELECT film_id, title\n')]
the output don't select all the queries. what should I do?