Skip to content
Snippets Groups Projects
Commit 3d015b07 authored by Marco Malavolti's avatar Marco Malavolti
Browse files

First incomplete log parsing script developed

parent 3e6bbb74
Branches
No related tags found
No related merge requests found
import logging
import json
from datetime import datetime
def main():
logging.basicConfig(filename='/home/eccs/logs/eccs-log-parsing.log', level=logging.INFO)
logging.info('Started')
file_name = "/home/eccs/logs/eccs-uwsgi.log"
file = open(file_name, "r")
data = []
order = ["ip", "date", "http-method", "url"]
for line in file.readlines():
if ("|" not in line): continue
details = line.split("|")
details = [x.strip() for x in details]
details[1] = datetime.strptime(details[1], '[%a %b %d %H:%M:%S %Y]').strftime('%Y-%m-%d')
structure = {key:value for key, value in zip(order, details)}
data.append(structure)
for entry in data:
print(json.dumps(entry, indent = 4))
logging.info('Finished')
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment