parse file-by-file
=> improved debugging capabilities (find corrupt log-files)
This commit is contained in:
parent
abf03d2fc7
commit
7f971acfa5
16
tsstats.py
16
tsstats.py
|
@ -179,15 +179,13 @@ def parse_logs(log_path, ident_map={}, file_log=False):
|
||||||
stream_handler.setLevel(logging.INFO)
|
stream_handler.setLevel(logging.INFO)
|
||||||
log.addHandler(stream_handler)
|
log.addHandler(stream_handler)
|
||||||
|
|
||||||
# find all log-files and collect lines
|
# find all log-files and open them
|
||||||
log_files = [file_name for file_name in glob.glob(log_path)]
|
log_files = [open(file_name) for file_name in glob.glob(log_path)]
|
||||||
log_lines = []
|
|
||||||
for log_file in log_files:
|
|
||||||
for line in open(log_file, 'r'):
|
|
||||||
log_lines.append(line)
|
|
||||||
|
|
||||||
|
for log_file in log_files:
|
||||||
# process lines
|
# process lines
|
||||||
for line in log_lines:
|
logging.debug('Started parsing of {}'.format(log_file.name))
|
||||||
|
for line in log_file:
|
||||||
parts = line.split('|')
|
parts = line.split('|')
|
||||||
log_format = '%Y-%m-%d %H:%M:%S.%f'
|
log_format = '%Y-%m-%d %H:%M:%S.%f'
|
||||||
stripped_time = datetime.datetime.strptime(parts[0], log_format)
|
stripped_time = datetime.datetime.strptime(parts[0], log_format)
|
||||||
|
@ -204,7 +202,8 @@ def parse_logs(log_path, ident_map={}, file_log=False):
|
||||||
client.nick = nick
|
client.nick = nick
|
||||||
client.disconnect(logdatetime)
|
client.disconnect(logdatetime)
|
||||||
if 'invokeruid' in data:
|
if 'invokeruid' in data:
|
||||||
re_disconnect_data = re_disconnect_invoker.findall(data)
|
re_disconnect_data = re_disconnect_invoker.findall(
|
||||||
|
data)
|
||||||
invokernick, invokeruid = re_disconnect_data[0]
|
invokernick, invokeruid = re_disconnect_data[0]
|
||||||
invoker = clients[invokeruid]
|
invoker = clients[invokeruid]
|
||||||
invoker.nick = invokernick
|
invoker.nick = invokernick
|
||||||
|
@ -212,6 +211,7 @@ def parse_logs(log_path, ident_map={}, file_log=False):
|
||||||
invoker.ban(client)
|
invoker.ban(client)
|
||||||
else:
|
else:
|
||||||
invoker.kick(client)
|
invoker.kick(client)
|
||||||
|
logging.debug('Finished parsing of {}'.format(log_file.name))
|
||||||
return clients
|
return clients
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue