Split logs by message python script
andrzejek
Polska
This simple script will split your log into separate files, create folder "output" and read from "input.txt":
from typing import List
LINES_REGISTRATION = [
'registration failed',
'unknown registration status',
'registration successful'
]
LINES = [
'download failed',
]
LINES_CAPTCHA = [
'ReCaptcha v2',
]
ALL_LINES = \
LINES_REGISTRATION + LINES + LINES_CAPTCHA
def get_file_map(lines: List[str]) -> List[dict]:
return [{
'file': open(f"./output/{x}.txt", encoding='utf-8', mode='a+'),
'file_urls': open(f"./output/{x}_urls.txt", encoding='utf-8', mode='a+'),
'line': x,
} for x in lines]
if __name__ == '__main__':
file_map = get_file_map(ALL_LINES)
with open("./input.txt") as file:
for line in file:
for d in file_map:
if d['line'] in line:
d['file'].write(line)
log_split = line.split(' ')
if 'http' in log_split[-1]:
d['file_urls'].write(log_split[-1]) # It would be cool to modify SER with python
Comments