Last active
May 23, 2017 08:23
-
-
Save geeksambhu/3a749aed307e44fa5e188bec46ee56f4 to your computer and use it in GitHub Desktop.
jpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
class LogProcess: | |
DATE_REGEX = r"\d{4}\-\d{1,2}\-\d{1,2}" | |
LOG_LEVEL_REGEX = r"(?<=\[)\w+(?=\])" | |
def __init__(self, filename): | |
self.logfile = filename | |
self.data = {} | |
self.logvalues = {} | |
self.validity = True | |
def is_valid(self): | |
self.validity | |
def proc1(self): | |
# print("geda jasto") | |
self.parse() | |
self.display() | |
# print(self.data) | |
def parse(self): | |
f = open(self.logfile) | |
for line in f: | |
self.parse_line(line) | |
f.close() | |
if self.validity == False: | |
return False | |
def parse_line(self, line): | |
date = re.findall( self.DATE_REGEX,line)[0] | |
log_level = re.findall(self.LOG_LEVEL_REGEX,line)[0] | |
if date not in self.data.keys(): | |
self.data={date:{'error':0,'warning':0} for date in re.findall( self.DATE_REGEX,line)} | |
self.logvalues = dict(self.logvalues.items()+self.data.items()) | |
for key,values in self.data.items(): | |
for k,v in values.items(): | |
if key == date and k ==log_level: | |
self.data[date][k] += 1 | |
def display(self): | |
for key,value in self.logvalues.items(): | |
print(key) | |
print(key,"warning:",value["warning"],"error:",value["error"]) | |
# print("True") | |
# print(self.logvalues) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logprocessor | |
import sys | |
instantiate= logprocessor.LogProcess("example.log") | |
instantiate.proc1(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment