Currently i'm reading all files in a folder and based on logs i'm getting Error and success count of products. It was working until yesterday. Each log file used to have information about single product but due to some technical glitch we started getting 2 products in a single file. We have fixed the issue for future. But we need to have the below data for our analytics purpose.
FileA
2022-03-28T11:53:50 Program Start
2022-03-28T11:53:50 PRODUCT "Screw"
2022-03-28T11:53:51 Code Executing
2022-03-28T11:53:51 ERROR
2022-03-28T11:53:52 Checking other stuffs like Order,Location....
FileB
2022-03-28T11:54:00 Program Start
2022-03-28T11:54:00 PRODUCT "Nut"
2022-03-28T11:54:01 Code Executing
2022-03-28T11:54:01 SUCCESS
2022-03-28T11:54:01 Checking other stuffs like Order,Location....
FileC
2022-03-28T11:55:01 Program Start
2022-03-28T11:55:01 PRODUCT "Washer"
2022-03-28T11:55:02 Code Executing
2022-03-28T11:55:02 ERROR
2022-03-28T11:55:02 Checking other stuffs like Order,Location....
2022-03-28T11:56:01 Program Start
2022-03-28T11:56:01 PRODUCT "Bolt"
2022-03-28T11:56:01 Code Executing
2022-03-28T11:56:01 SUCCESS
2022-03-28T11:56:02 Checking other stuffs like Order,Location....
Expected output -> Total : 4 Success : 2 Failed : 2
Also i'm taking product information and other details and writing in separate files. so it is not only count of success and errors
Success Failed OrderNo
Nut Screw 1098
Bolt Washer ...
Code i have developed to get the output
import os
import re
path = "\\\\myserver\logs"
files = os.listdir(path)
for file in files:
if file.endswith(".log"):
f = '/'.join([path,file])
with open(f, encoding='utf8') as f:
count += 1
content = f.read()
if 'ERROR' in content:
err +=1
else:
pss+=1
print("Total-->",count)
print("Success-->",pss)
print("Failed-->",err)
Current Output -> Total : 3 Success : 1 Failed : 2
I have tried splitting and reading the file by following this post but with no success. Program Start
is the keyword for splitting. I have only read access to this log path, i cannot save anything. Is there a way i can achieve this on the fly? i have only limited knowledge in python. Appreciate your guidance here.