Mercurial > traipse_dev
comparison orpg/tools/orpg_log.py @ 79:dd4be4817377 ornery-dev
Chat Window no longer prints excessive debug statements to console. Renamed the Update Manager menu item to Traipse Suite. Added debug console to Traipse Suite. Log now prints an error report and waits for user input so Windows users can see the error being reported.
author | sirebral |
---|---|
date | Sun, 23 Aug 2009 14:57:06 -0500 |
parents | c54768cffbd4 |
children | 65c212e9a5b4 |
comparison
equal
deleted
inserted
replaced
78:57887ab0df51 | 79:dd4be4817377 |
---|---|
23 # Version: | 23 # Version: |
24 # $Id: orpg_log.py,v 1.9 2007/05/06 16:43:02 digitalxero Exp $ | 24 # $Id: orpg_log.py,v 1.9 2007/05/06 16:43:02 digitalxero Exp $ |
25 # | 25 # |
26 # Description: classes for orpg log messages | 26 # Description: classes for orpg log messages |
27 # | 27 # |
28 | |
28 from __future__ import with_statement | 29 from __future__ import with_statement |
29 import sys | 30 import sys, os, os.path, wx, time, traceback |
30 import os, os.path | |
31 import time | |
32 | 31 |
32 from orpg.orpgCore import component | |
33 from orpg.external.terminalwriter import TerminalWriter | 33 from orpg.external.terminalwriter import TerminalWriter |
34 from orpg.tools.decorators import pending_deprecation | 34 from orpg.tools.decorators import pending_deprecation |
35 from orpg.dirpath import dir_struct | 35 from orpg.dirpath import dir_struct |
36 | 36 |
37 ######################### | 37 ######################### |
40 ORPG_CRITICAL = 1 | 40 ORPG_CRITICAL = 1 |
41 ORPG_GENERAL = 2 | 41 ORPG_GENERAL = 2 |
42 ORPG_INFO = 4 | 42 ORPG_INFO = 4 |
43 ORPG_NOTE = 8 | 43 ORPG_NOTE = 8 |
44 ORPG_DEBUG = 16 | 44 ORPG_DEBUG = 16 |
45 | |
46 def Crash(type, value, crash): | |
47 crash_report = open(dir_struct["home"] + 'crash-report.txt', "w") | |
48 traceback.print_exception(type, value, crash, file=crash_report) | |
49 crash_report.close() | |
50 msg = '' | |
51 crash_report = open(dir_struct["home"] + 'crash-report.txt', "r") | |
52 for line in crash_report: msg += line | |
53 logger.exception(msg) | |
54 crash_report.close() | |
55 logger.exception("Crash Report Created!!") | |
56 logger.info("Printed out a datafile called crash-report.txt\nPress <enter> to exit!", True); raw_input('') | |
57 exit() | |
58 | |
59 class DebugConsole(wx.Frame): | |
60 def __init__(self, parent): | |
61 super(DebugConsole, self).__init__(parent, -1, "Debug Window") | |
62 icon = None | |
63 icon = wx.Icon(dir_struct["icon"]+'note.ico', wx.BITMAP_TYPE_ICO) | |
64 self.SetIcon( icon ) | |
65 self.console = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE | wx.TE_READONLY) | |
66 sizer = wx.BoxSizer(wx.VERTICAL) | |
67 sizer.Add(self.console, 1, wx.EXPAND) | |
68 self.SetSizer(sizer) | |
69 self.SetAutoLayout(True) | |
70 self.SetSize((300, 175)) | |
71 self.Bind(wx.EVT_CLOSE, self.Min) | |
72 self.Min(None) | |
73 component.add('debugger', self.console) | |
74 | |
75 def Min(self, evt): | |
76 self.Hide() | |
45 | 77 |
46 class orpgLog(object): | 78 class orpgLog(object): |
47 _log_level = 7 | 79 _log_level = 7 |
48 _log_name = None | 80 _log_name = None |
49 _log_to_console = False | 81 _log_to_console = False |
88 self.log(msg, ORPG_CRITICAL, to_console) | 120 self.log(msg, ORPG_CRITICAL, to_console) |
89 | 121 |
90 def log(self, msg, log_type, to_console=False): | 122 def log(self, msg, log_type, to_console=False): |
91 if self.log_to_console or to_console or log_type == ORPG_CRITICAL: | 123 if self.log_to_console or to_console or log_type == ORPG_CRITICAL: |
92 self._io.line(str(msg), **self._lvl_args[log_type]['colorizer']) | 124 self._io.line(str(msg), **self._lvl_args[log_type]['colorizer']) |
93 | 125 try: component.get('debugger').AppendText(".. " + str(msg) +'\n') |
126 except: pass | |
94 | 127 |
95 if log_type & self.log_level or to_console: | 128 if log_type & self.log_level or to_console: |
96 atr = {'msg': msg, 'level': self._lvl_args[log_type]['log_string']} | 129 atr = {'msg': msg, 'level': self._lvl_args[log_type]['log_string']} |
97 atr['time'] = time.strftime('[%x %X]', time.localtime(time.time())) | 130 atr['time'] = time.strftime('[%x %X]', time.localtime(time.time())) |
98 logMsg = '%(time)s (%(level)s) - %(msg)s\n' % (atr) | 131 logMsg = '%(time)s (%(level)s) - %(msg)s\n' % (atr) |
154 log_level = property(_get_log_level, _set_log_level) | 187 log_level = property(_get_log_level, _set_log_level) |
155 log_name = property(_get_log_name, _set_log_name) | 188 log_name = property(_get_log_name, _set_log_name) |
156 log_to_console = property(_get_log_to_console, _set_log_to_console) | 189 log_to_console = property(_get_log_to_console, _set_log_to_console) |
157 | 190 |
158 logger = orpgLog(dir_struct.get("user") + "runlogs/") | 191 logger = orpgLog(dir_struct.get("user") + "runlogs/") |
192 crash = sys.excepthook = Crash |