Skip to content

Commit

Permalink
Issue #21: Added code to pipe log messages from ActionScript to pytho…
Browse files Browse the repository at this point in the history
…n.log.
  • Loading branch information
Janne Hakonen committed Mar 22, 2016
1 parent 59e6d44 commit 801b472
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions settingsui/src/SettingsUI.as
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,25 @@ package
public class SettingsUI extends AbstractWindowView {
public function SettingsUI() {
super();
DebugUtils.LOG_WARNING("TESSUMOD :: SettingsUI :: in constructor");
}

override protected function configUI(): void {
super.configUI();
DebugUtils.LOG_WARNING("TESSUMOD :: SettingsUI :: in configUI()");
}

override protected function onPopulate(): void {
super.onPopulate();
this.width = 600;
this.height = 400;
this.window.title = "Settings UI";
DebugUtils.LOG_WARNING("TESSUMOD :: SettingsUI :: in onPopulate()");
}

override protected function onDispose(): void {
super.onDispose();
DebugUtils.LOG_WARNING("TESSUMOD :: SettingsUI :: in onDispose()");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import BigWorld
from gui import SystemMessages, InputHandler
from gui.app_loader import g_appLoader
from gui.shared import g_eventBus, events
from gui.shared.notifications import NotificationGuiSettings
from gui.shared.utils.key_mapping import getBigworldNameFromKey
from gui.Scaleform.daapi import LobbySubView
Expand Down Expand Up @@ -67,6 +68,15 @@ def error(msg, *args):
if log.CURRENT_LOG_LEVEL <= log.LOG_LEVEL.ERROR:
_doLog('ERROR', log.prefix_with_timestamp(msg), args)

@staticmethod
def gui(type, *args):
if type == "DEBUG" and log.CURRENT_LOG_LEVEL <= log.LOG_LEVEL.DEBUG:
_doLog("GUI", "{}.GUI".format(type), args)
elif type == "WARNING" and log.CURRENT_LOG_LEVEL <= log.LOG_LEVEL.WARNING:
_doLog("GUI", "{}.GUI".format(type), args)
elif type == "ERROR" and log.CURRENT_LOG_LEVEL <= log.LOG_LEVEL.ERROR:
_doLog("GUI", "{}.GUI".format(type), args)

@staticmethod
def exception():
msg = _makeMsgHeader(sys._getframe(1)) + "\n"
Expand Down Expand Up @@ -503,3 +513,20 @@ def onhandleKeyEvent(event):
g_appLoader.getApp().loadView(SettingsUIWindow.NAME, SettingsUIWindow.NAME)
return None
InputHandler.g_instance.onKeyDown += onhandleKeyEvent

# HACK: get GUI debug messages to appear to python.log
def onAppInitialized(event):
from gui.app_loader import g_appLoader
app = g_appLoader.getDefLobbyApp()
app.addExternalCallback('debug.LOG_GUI', on_log_gui)
app.addExternalCallback('debug.LOG_GUI_FORMAT', on_log_gui_format)

def on_log_gui(type, msg, *args):
if "tessumod" in msg.lower():
log.LOG_GUI(str(type), msg, args)

def on_log_gui_format(type, msg, *args):
if "tessumod" in msg.lower():
log.LOG_GUI(str(type), msg % args)

g_eventBus.addListener(events.AppLifeCycleEvent.INITIALIZED, onAppInitialized)
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ class LOG_LEVEL(object):
CURRENT_LOG_LEVEL = LOG_LEVEL.NOTE

def install_logger_impl(impl):
global LOG_DEBUG, LOG_DEBUG, LOG_NOTE, LOG_WARNING, LOG_ERROR, LOG_CURRENT_EXCEPTION
global LOG_DEBUG, LOG_DEBUG, LOG_NOTE, LOG_WARNING, LOG_ERROR, LOG_GUI, LOG_CURRENT_EXCEPTION
LOG_DEBUG = impl.debug
LOG_NOTE = impl.note
LOG_WARNING = impl.warning
LOG_ERROR = impl.error
LOG_GUI = impl.gui
LOG_CURRENT_EXCEPTION = impl.exception

def LOG_DEBUG(msg, *args):
Expand All @@ -46,6 +47,9 @@ def LOG_WARNING(msg, *args):
def LOG_ERROR(msg, *args):
print msg

def LOG_GUI(type, msg, *args):
print type, msg

def LOG_CURRENT_EXCEPTION():
print traceback.format_exc()

Expand Down

0 comments on commit 801b472

Please sign in to comment.