From 45c7d1e393f760ab0ea4dcf9a95fec686504b618 Mon Sep 17 00:00:00 2001 From: Gabor Guzmics Date: Wed, 15 Apr 2015 00:57:59 +0200 Subject: [PATCH] * 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. --- analyze.py | 6 +++++- logs/base.py | 6 ++++-- logs/combat.py | 3 ++- logs/logfile.py | 2 +- logs/logstream.py | 19 +++++++++++++------ 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/analyze.py b/analyze.py index f8cf778..5913e69 100644 --- a/analyze.py +++ b/analyze.py @@ -23,6 +23,10 @@ settings = {'root_path': os.path.join(os.path.expanduser('~'), 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() @@ -30,7 +34,7 @@ if __name__ == '__main__': rex_combat = {} rex_game = {} rex_chat = {} - LOG_GOOD = True + LOG_GOOD = True # Log good packets. for logf in coll.sessions: logf.parse_files(['game.log', 'combat.log', 'chat.log']) diff --git a/logs/base.py b/logs/base.py index f1e80c6..fd95e7f 100644 --- a/logs/base.py +++ b/logs/base.py @@ -1,3 +1,4 @@ +import logging L_CMBT = 'CMBT' L_WARNING = 'WARNING' @@ -56,5 +57,6 @@ class Stacktrace(Log): def append(self, something): ''' I take anything! ''' - print "EXC: %s" % something - self.message = '%s\n%s' % (self.message, something) \ No newline at end of file + logging.debug( "EXC: %s" % something ) + self.message = '%s\n%s' % (self.message, something) + return True \ No newline at end of file diff --git a/logs/combat.py b/logs/combat.py index f0a0eba..ac86ef0 100644 --- a/logs/combat.py +++ b/logs/combat.py @@ -22,6 +22,7 @@ """ import re from base import Log, L_CMBT, Stacktrace +import logging class CombatLog(Log): __slots__ = Log.__slots__ + [ '_match_id', 'values'] @@ -215,7 +216,7 @@ class UserEvent(CombatLog): if line and 'earned medal' in line: return True elif line: - print line + logging.debug('UserEvent saw unknown line: %s' % line) return False # Action? diff --git a/logs/logfile.py b/logs/logfile.py index 43f8469..aded160 100644 --- a/logs/logfile.py +++ b/logs/logfile.py @@ -41,7 +41,7 @@ class LogFile(LogStream): lines = [] if self.has_data(): data_lines = self.get_data( - #).replace('\r', '\n' + ).replace('\r', '\n' ).replace('\n\n', '\n' ).split('\n' ) diff --git a/logs/logstream.py b/logs/logstream.py index 7305d70..599b9ef 100644 --- a/logs/logstream.py +++ b/logs/logstream.py @@ -29,6 +29,7 @@ from .base import Log import re from logs.base import Stacktrace +import logging RE_SCLOG = r'^(?P\d{2,2})\:(?P\d{2,2})\:(?P\d{2,2})\.(?P\d{3,3})\s(?P\s*[^\|\s]+\s*|\s+)\|\s(?P.*)' R_SCLOG = re.compile(RE_SCLOG) @@ -87,6 +88,10 @@ class LogStream(object): return line elif line.startswith('---'): return None + elif line == '' or line == '\n': + if line == '\n': + logging.debug('Empty Newline detected.') + return None else: # get the timecode & logtype m = R_SCLOG.match(line) @@ -96,8 +101,6 @@ class LogStream(object): g['logtype'] = g['logtype'].strip() return g else: - #if line: - # print line return line return None @@ -109,15 +112,19 @@ class LogStream(object): # Unknown Log? if not line: return - if self._last_object is not None: - self._last_object.unpack() - if self._last_object.append(line): - return # It might be a stacktrace. inject it./ if Stacktrace.is_handler(o): o = Stacktrace(o) self._last_object = o else: + #if isinstance(self._last_object, Stacktrace) and line.startswith('\t'): + # logging.debug('Workaround: %s, worked: %s' % (line, self._last_object.append(line))) + # return + if self._last_object is not None: + self._last_object.unpack() + if self._last_object.append(line): + return + logging.debug('>> %s' % line) o = None elif isinstance(line, dict): # Unresolved Log.