scon/analyze.py
Gabor Guzmics 45c7d1e393 * fix in stacktrace made it work.
* added debug config to analyze.
= from now on logging.debug should be utilized to remark stuff, so final
implementations can ignore such messages.
2015-04-15 00:57:59 +02:00

87 lines
3.4 KiB
Python

#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Tool to analyze Logs in general.
"""
import os, sys, logging
from logs.logfiles import LogFileResolver as LogFile
from logs import combat, game, chat
from logs.session import LogSessionCollector
from logs.game import ClientInfo
# for windows its kinda this:
settings = {'root_path': os.path.join(os.path.expanduser('~'),
'Documents',
'My Games',
'StarConflict',),
'logfiles': os.path.join(os.path.expanduser('~'),
'Documents',
'My Games',
'StarConflict',
'logs'
)}
if __name__ == '__main__':
import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
coll = LogSessionCollector(os.path.join(os.path.expanduser('~'),
'Documents', 'My Games', 'sc'))
coll.collect_unique()
#f = open('output.txt', 'w')
rex_combat = {}
rex_game = {}
rex_chat = {}
LOG_GOOD = True # Log good packets.
for logf in coll.sessions:
logf.parse_files(['game.log', 'combat.log', 'chat.log'])
print "----- Log %s -----" % logf.idstr
if logf.combat_log:
for l in logf.combat_log.lines:
if isinstance(l, dict):
#print l
rex_combat['dict'] = rex_combat.get('dict', 0) + 1
else:
if not l.unpack() or LOG_GOOD:
rex_combat[l.__class__.__name__] = rex_combat.get(l.__class__.__name__, 0) + 1
if not isinstance(l, combat.UserEvent):
if not LOG_GOOD:
print l.values['log']
if logf.game_log:
for l in logf.game_log.lines:
if isinstance(l, dict):
rex_game['dict'] = rex_game.get('dict', 0) + 1
elif isinstance(l, str):
print l
else:
if l.unpack() and not LOG_GOOD:
pass
else:
rex_game[l.__class__.__name__] = rex_game.get(l.__class__.__name__, 0) + 1
if not LOG_GOOD:
print l.values['log']
if logf.chat_log:
for l in logf.chat_log.lines:
if isinstance(l, dict):
rex_chat['dict'] = rex_chat.get('dict', 0) + 1
elif isinstance(l, str):
print l
else:
if l.unpack() and not LOG_GOOD:
pass
else:
rex_chat[l.__class__.__name__] = rex_chat.get(l.__class__.__name__, 0) + 1
if not LOG_GOOD:
print l.values['log']
logf.clean(True)
print 'Analysis complete:'
print '#'*20+' RexCombat ' + '#' *20
print rex_combat
print '#'*20+' RexGame ' + '#' *20
print rex_game
print '#'*20+' RexChat ' + '#' *20
print rex_chat