* 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.
This commit is contained in:
Gabor Körber 2015-04-15 00:57:59 +02:00
parent 9bfdd1fb7a
commit 45c7d1e393
5 changed files with 25 additions and 11 deletions

View File

@ -23,6 +23,10 @@ settings = {'root_path': os.path.join(os.path.expanduser('~'),
if __name__ == '__main__': 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('~'), coll = LogSessionCollector(os.path.join(os.path.expanduser('~'),
'Documents', 'My Games', 'sc')) 'Documents', 'My Games', 'sc'))
coll.collect_unique() coll.collect_unique()
@ -30,7 +34,7 @@ if __name__ == '__main__':
rex_combat = {} rex_combat = {}
rex_game = {} rex_game = {}
rex_chat = {} rex_chat = {}
LOG_GOOD = True LOG_GOOD = True # Log good packets.
for logf in coll.sessions: for logf in coll.sessions:
logf.parse_files(['game.log', 'combat.log', 'chat.log']) logf.parse_files(['game.log', 'combat.log', 'chat.log'])

View File

@ -1,3 +1,4 @@
import logging
L_CMBT = 'CMBT' L_CMBT = 'CMBT'
L_WARNING = 'WARNING' L_WARNING = 'WARNING'
@ -56,5 +57,6 @@ class Stacktrace(Log):
def append(self, something): def append(self, something):
''' I take anything! ''' ''' I take anything! '''
print "EXC: %s" % something logging.debug( "EXC: %s" % something )
self.message = '%s\n%s' % (self.message, something) self.message = '%s\n%s' % (self.message, something)
return True

View File

@ -22,6 +22,7 @@
""" """
import re import re
from base import Log, L_CMBT, Stacktrace from base import Log, L_CMBT, Stacktrace
import logging
class CombatLog(Log): class CombatLog(Log):
__slots__ = Log.__slots__ + [ '_match_id', 'values'] __slots__ = Log.__slots__ + [ '_match_id', 'values']
@ -215,7 +216,7 @@ class UserEvent(CombatLog):
if line and 'earned medal' in line: if line and 'earned medal' in line:
return True return True
elif line: elif line:
print line logging.debug('UserEvent saw unknown line: %s' % line)
return False return False
# Action? # Action?

View File

@ -41,7 +41,7 @@ class LogFile(LogStream):
lines = [] lines = []
if self.has_data(): if self.has_data():
data_lines = self.get_data( data_lines = self.get_data(
#).replace('\r', '\n' ).replace('\r', '\n'
).replace('\n\n', '\n' ).replace('\n\n', '\n'
).split('\n' ).split('\n'
) )

View File

@ -29,6 +29,7 @@
from .base import Log from .base import Log
import re import re
from logs.base import Stacktrace from logs.base import Stacktrace
import logging
RE_SCLOG = r'^(?P<hh>\d{2,2})\:(?P<mm>\d{2,2})\:(?P<ss>\d{2,2})\.(?P<ns>\d{3,3})\s(?P<logtype>\s*[^\|\s]+\s*|\s+)\|\s(?P<log>.*)' RE_SCLOG = r'^(?P<hh>\d{2,2})\:(?P<mm>\d{2,2})\:(?P<ss>\d{2,2})\.(?P<ns>\d{3,3})\s(?P<logtype>\s*[^\|\s]+\s*|\s+)\|\s(?P<log>.*)'
R_SCLOG = re.compile(RE_SCLOG) R_SCLOG = re.compile(RE_SCLOG)
@ -87,6 +88,10 @@ class LogStream(object):
return line return line
elif line.startswith('---'): elif line.startswith('---'):
return None return None
elif line == '' or line == '\n':
if line == '\n':
logging.debug('Empty Newline detected.')
return None
else: else:
# get the timecode & logtype # get the timecode & logtype
m = R_SCLOG.match(line) m = R_SCLOG.match(line)
@ -96,8 +101,6 @@ class LogStream(object):
g['logtype'] = g['logtype'].strip() g['logtype'] = g['logtype'].strip()
return g return g
else: else:
#if line:
# print line
return line return line
return None return None
@ -109,15 +112,19 @@ class LogStream(object):
# Unknown Log? # Unknown Log?
if not line: if not line:
return 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./ # It might be a stacktrace. inject it./
if Stacktrace.is_handler(o): if Stacktrace.is_handler(o):
o = Stacktrace(o) o = Stacktrace(o)
self._last_object = o self._last_object = o
else: 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 o = None
elif isinstance(line, dict): elif isinstance(line, dict):
# Unresolved Log. # Unresolved Log.