From: epage Date: Mon, 28 Sep 2009 22:55:16 +0000 (+0000) Subject: Switched to module level loggers X-Git-Url: http://git.maemo.org/git/?p=gc-dialer;a=commitdiff_plain;h=f40854ec9cdac528f81ca2414d202d980cd486df Switched to module level loggers git-svn-id: file:///svnroot/gc-dialer/trunk@487 c39d3808-3fe2-4d86-a59f-b7f623ee9f21 --- diff --git a/src/browser_emu.py b/src/browser_emu.py index 88a0b62..32ffbca 100644 --- a/src/browser_emu.py +++ b/src/browser_emu.py @@ -32,6 +32,7 @@ import logging import socket +_moduleLogger = logging.getLogger("browser_emu") socket.setdefaulttimeout(10) @@ -100,7 +101,7 @@ class MozillaEmulator(object): @return: The raw HTML page data """ - logging.warning("Performing download of %s" % url) + _moduleLogger.warning("Performing download of %s" % url) if extraheaders is None: extraheaders = {} @@ -113,9 +114,9 @@ class MozillaEmulator(object): req, u = self.build_opener(url, postdata, extraheaders, forbid_redirect) openerdirector = u.open(req) if self.debug: - print req.get_method(), url - print openerdirector.code, openerdirector.msg - print openerdirector.headers + _moduleLogger.info("%r - %r" % (req.get_method(), url)) + _moduleLogger.info("%r - %r" % (openerdirector.code, openerdirector.msg)) + _moduleLogger.info("%r" % (openerdirector.headers)) self.cookies.extract_cookies(openerdirector, req) if only_head: return openerdirector @@ -127,8 +128,7 @@ class MozillaEmulator(object): raise # Retry :-) - if self.debug: - print "MozillaEmulator: urllib2.URLError, retryting ", cnt + _moduleLogger.info("MozillaEmulator: urllib2.URLError, retryting %d" % cnt) def _read(self, openerdirector, trycount): chunks = [] diff --git a/src/dc_glade.py b/src/dc_glade.py index b23521a..1c1f6da 100755 --- a/src/dc_glade.py +++ b/src/dc_glade.py @@ -41,6 +41,9 @@ import hildonize import gtk_toolbox +_moduleLogger = logging.getLogger("dc_glade") + + def getmtime_nothrow(path): try: return os.path.getmtime(path) @@ -138,7 +141,7 @@ class Dialcentral(object): self._window.connect("key-press-event", self._on_key_press) self._window.connect("window-state-event", self._on_window_state_change) if not hildonize.IS_HILDON_SUPPORTED: - logging.warning("No hildonization support") + _moduleLogger.warning("No hildonization support") hildonize.set_application_title(self._window, "%s" % constants.__pretty_app_name__) @@ -195,7 +198,7 @@ class Dialcentral(object): device = osso.DeviceState(self._osso) device.set_device_state_callback(self._on_device_state_change, 0) else: - logging.warning("No device state support") + _moduleLogger.warning("No device state support") try: import alarm_handler @@ -206,13 +209,13 @@ class Dialcentral(object): with gtk_toolbox.gtk_lock(): self._errorDisplay.push_exception() alarm_handler = None - logging.warning("No notification support") + _moduleLogger.warning("No notification support") if hildonize.IS_HILDON_SUPPORTED: try: import led_handler self._ledHandler = led_handler.LedHandler() except Exception, e: - logging.exception('LED Handling failed: "%s"' % str(e)) + _moduleLogger.exception('LED Handling failed: "%s"' % str(e)) self._ledHandler = None else: self._ledHandler = None @@ -227,7 +230,7 @@ class Dialcentral(object): self._connection.connect("connection-event", self._on_connection_change, constants.__app_magic__) self._connection.request_connection(conic.CONNECT_FLAG_NONE) else: - logging.warning("No connection support") + _moduleLogger.warning("No connection support") except Exception, e: with gtk_toolbox.gtk_lock(): self._errorDisplay.push_exception() @@ -346,7 +349,7 @@ class Dialcentral(object): serviceId = self._defaultBackendId loggedIn = True except Exception, e: - logging.exception('Session refresh failed with the following message "%s"' % str(e)) + _moduleLogger.exception('Session refresh failed with the following message "%s"' % str(e)) if not loggedIn: loggedIn, serviceId = self._login_by_user(numOfAttempts) @@ -380,7 +383,7 @@ class Dialcentral(object): """ loggedIn = self._phoneBackends[self._defaultBackendId].is_authed() if loggedIn: - logging.info("Logged into %r through cookies" % self._phoneBackends[self._defaultBackendId]) + _moduleLogger.info("Logged into %r through cookies" % self._phoneBackends[self._defaultBackendId]) return loggedIn def _login_by_settings(self): @@ -391,7 +394,7 @@ class Dialcentral(object): loggedIn = self._phoneBackends[self._defaultBackendId].login(username, password) if loggedIn: self._credentials = username, password - logging.info("Logged into %r through settings" % self._phoneBackends[self._defaultBackendId]) + _moduleLogger.info("Logged into %r through settings" % self._phoneBackends[self._defaultBackendId]) return loggedIn def _login_by_user(self, numOfAttempts): @@ -416,7 +419,7 @@ class Dialcentral(object): if loggedIn: serviceId = tmpServiceId self._credentials = username, password - logging.info("Logged into %r through user request" % self._phoneBackends[serviceId]) + _moduleLogger.info("Logged into %r through user request" % self._phoneBackends[serviceId]) else: serviceId = self.NULL_BACKEND self._notebook.set_current_page(self.ACCOUNT_TAB) @@ -479,14 +482,14 @@ class Dialcentral(object): if self._alarmHandler is not None: self._alarmHandler.load_settings(config, "alarm") except ConfigParser.NoOptionError, e: - logging.exception( + _moduleLogger.exception( "Settings file %s is missing section %s" % ( constants._user_settings_, e.section, ), ) except ConfigParser.NoSectionError, e: - logging.exception( + _moduleLogger.exception( "Settings file %s is missing section %s" % ( constants._user_settings_, e.section, @@ -504,14 +507,14 @@ class Dialcentral(object): try: view.load_settings(config, sectionName) except ConfigParser.NoOptionError, e: - logging.exception( + _moduleLogger.exception( "Settings file %s is missing section %s" % ( constants._user_settings_, e.section, ), ) except ConfigParser.NoSectionError, e: - logging.exception( + _moduleLogger.exception( "Settings file %s is missing section %s" % ( constants._user_settings_, e.section, @@ -525,14 +528,14 @@ class Dialcentral(object): elif previousOrientation == gtk.ORIENTATION_VERTICAL: hildonize.window_to_portrait(self._window) except ConfigParser.NoOptionError, e: - logging.exception( + _moduleLogger.exception( "Settings file %s is missing section %s" % ( constants._user_settings_, e.section, ), ) except ConfigParser.NoSectionError, e: - logging.exception( + _moduleLogger.exception( "Settings file %s is missing section %s" % ( constants._user_settings_, e.section, diff --git a/src/dialcentral.py b/src/dialcentral.py index 4f669ff..e29f311 100755 --- a/src/dialcentral.py +++ b/src/dialcentral.py @@ -5,6 +5,7 @@ import sys import logging +_moduleLogger = logging.getLogger("dialcentral") sys.path.insert(0,"/usr/lib/dialcentral/") @@ -20,7 +21,7 @@ except OSError, e: userLogPath = "%s/dialcentral.log" % constants._data_path_ logging.basicConfig(level=logging.DEBUG, filename=userLogPath) -logging.info("Dialcentral %s-%s" % (constants.__version__, constants.__build__)) +_moduleLogger.info("Dialcentral %s-%s" % (constants.__version__, constants.__build__)) try: dc_glade.run_dialpad() diff --git a/src/gtk_toolbox.py b/src/gtk_toolbox.py index 26803d7..575da00 100644 --- a/src/gtk_toolbox.py +++ b/src/gtk_toolbox.py @@ -17,6 +17,9 @@ import gobject import gtk +_moduleLogger = logging.getLogger("gtk_toolbox") + + def get_screen_orientation(): width, height = gtk.gdk.get_default_root_window().get_size() if width < height: @@ -215,7 +218,7 @@ def comap(function, target): mappedItem = function(*item) target.send(mappedItem) except Exception, e: - logging.exception("Forwarding exception!") + _moduleLogger.exception("Forwarding exception!") target.throw(e.__class__, str(e)) @@ -423,7 +426,7 @@ class ErrorDisplay(object): def push_exception(self): userMessage = str(sys.exc_info()[1]) self.push_message(userMessage) - logging.exception(userMessage) + _moduleLogger.exception(userMessage) def pop_message(self): del self.__messages[0] @@ -463,7 +466,7 @@ class DummyErrorDisplay(object): def push_exception(self, exception = None): userMessage = str(sys.exc_value) - logging.exception(userMessage) + _moduleLogger.exception(userMessage) def pop_message(self): if 0 < len(self.__messages): @@ -471,7 +474,7 @@ class DummyErrorDisplay(object): del self.__messages[0] def __show_message(self, message): - logging.debug(message) + _moduleLogger.debug(message) class MessageBox(gtk.MessageDialog): @@ -545,7 +548,7 @@ class PopupCalendar(object): self._calendar.select_month(self._displayDate.month, self._displayDate.year) self._calendar.select_day(self._displayDate.day) except Exception, e: - logging.exception(e) + _moduleLogger.exception(e) class QuickAddView(object): diff --git a/src/gv_backend.py b/src/gv_backend.py index 0e5da67..4d6e19c 100644 --- a/src/gv_backend.py +++ b/src/gv_backend.py @@ -46,6 +46,7 @@ except ImportError: simplejson = None +_moduleLogger = logging.getLogger("gv_backend") _TRUE_REGEX = re.compile("true") _FALSE_REGEX = re.compile("false") @@ -133,7 +134,7 @@ class GVDialer(object): try: self._grab_account_info() except Exception, e: - logging.exception(str(e)) + _moduleLogger.exception(str(e)) return False self._browser.cookies.save() @@ -162,7 +163,7 @@ class GVDialer(object): try: loginSuccessOrFailurePage = self._browser.download(self._loginURL, loginPostData) except urllib2.URLError, e: - logging.exception(str(e)) + _moduleLogger.exception(str(e)) raise RuntimeError("%s is not accesible" % self._loginURL) return self.is_authed() @@ -193,7 +194,7 @@ class GVDialer(object): } callSuccessPage = self._browser.download(self._clicktocallURL, clickToCallData, None, otherData) except urllib2.URLError, e: - logging.exception(str(e)) + _moduleLogger.exception(str(e)) raise RuntimeError("%s is not accesible" % self._clicktocallURL) if self._gvDialingStrRe.search(callSuccessPage) is None: @@ -218,7 +219,7 @@ class GVDialer(object): } smsSuccessPage = self._browser.download(self._sendSmsURL, smsData, None, otherData) except urllib2.URLError, e: - logging.exception(str(e)) + _moduleLogger.exception(str(e)) raise RuntimeError("%s is not accesible" % self._sendSmsURL) return True @@ -339,7 +340,7 @@ class GVDialer(object): try: contactsPage = self._browser.download(contactsPageUrl) except urllib2.URLError, e: - logging.exception(str(e)) + _moduleLogger.exception(str(e)) raise RuntimeError("%s is not accesible" % contactsPageUrl) for contact_match in self._contactsRe.finditer(contactsPage): contactId = contact_match.group(1) @@ -366,7 +367,7 @@ class GVDialer(object): try: detailPage = self._browser.download(self._contactDetailURL + '/' + contactId) except urllib2.URLError, e: - logging.exception(str(e)) + _moduleLogger.exception(str(e)) raise RuntimeError("%s is not accesible" % self._contactDetailURL) for detail_match in self._contactDetailPhoneRe.finditer(detailPage): @@ -381,7 +382,7 @@ class GVDialer(object): try: voicemailPage = self._browser.download(self._voicemailURL) except urllib2.URLError, e: - logging.exception(str(e)) + _moduleLogger.exception(str(e)) raise RuntimeError("%s is not accesible" % self._voicemailURL) voicemailHtml = self._grab_html(voicemailPage) parsedVoicemail = self._parse_voicemail(voicemailHtml) @@ -390,7 +391,7 @@ class GVDialer(object): try: smsPage = self._browser.download(self._smsURL) except urllib2.URLError, e: - logging.exception(str(e)) + _moduleLogger.exception(str(e)) raise RuntimeError("%s is not accesible" % self._smsURL) smsHtml = self._grab_html(smsPage) parsedSms = self._parse_sms(smsHtml) @@ -432,7 +433,7 @@ class GVDialer(object): if anGroup is not None: self._accountNum = anGroup.group(1) else: - logging.debug("Could not extract account number from GoogleVoice") + _moduleLogger.debug("Could not extract account number from GoogleVoice") self._callbackNumbers = {} for match in self._callbackRe.finditer(page): @@ -468,7 +469,7 @@ class GVDialer(object): try: flatXml = self._browser.download(url) except urllib2.URLError, e: - logging.exception(str(e)) + _moduleLogger.exception(str(e)) raise RuntimeError("%s is not accesible" % url) allRecentHtml = self._grab_html(flatXml) diff --git a/src/gv_views.py b/src/gv_views.py index 0eac88b..21e126c 100644 --- a/src/gv_views.py +++ b/src/gv_views.py @@ -35,6 +35,9 @@ import hildonize import null_backend +_moduleLogger = logging.getLogger("gv_views") + + def make_ugly(prettynumber): """ function to take a phone number and strip out all non-numeric @@ -812,7 +815,7 @@ class AccountInfo(object): if not self._backend.is_valid_syntax(number) and 0 < len(number): self._errorDisplay.push_message("%s is not a valid callback number" % number) elif number == self._backend.get_callback_number(): - logging.warning( + _moduleLogger.warning( "Callback number already is %s" % ( self._backend.get_callback_number(), ), @@ -823,7 +826,7 @@ class AccountInfo(object): make_pretty(number), make_pretty(self._backend.get_callback_number()) ) self._callbackSelectButton.set_label(make_pretty(number)) - logging.info( + _moduleLogger.info( "Callback number set to %s" % ( self._backend.get_callback_number(), ), @@ -854,7 +857,7 @@ class AccountInfo(object): number = make_ugly(userSelection) self._set_callback_number(number) except RuntimeError, e: - logging.exception("%s" % str(e)) + _moduleLogger.exception("%s" % str(e)) except Exception, e: self._errorDisplay.push_exception() @@ -900,7 +903,7 @@ class AccountInfo(object): self._update_alarm_settings(recurrence) except RuntimeError, e: - logging.exception("%s" % str(e)) + _moduleLogger.exception("%s" % str(e)) except Exception, e: self._errorDisplay.push_exception() diff --git a/support/builddeb.py b/support/builddeb.py index c910be1..ec14d75 100755 --- a/support/builddeb.py +++ b/support/builddeb.py @@ -22,6 +22,9 @@ __email__ = "eopage@byu.net" __version__ = constants.__version__ __build__ = constants.__build__ __changelog__ = """ +1.0.7 +* Debugging: Improved logging output + 1.0.6 * Fremantle Prep: Simplified menus in prep for no menu or the Fremantle App Menu * Fremantle Prep: Implemented a work around for https://bugs.maemo.org/show_bug.cgi?id=4957 diff --git a/tests/gv_samples/generate_gv_samples.py b/tests/gv_samples/generate_gv_samples.py index dd7c82e..0953779 100755 --- a/tests/gv_samples/generate_gv_samples.py +++ b/tests/gv_samples/generate_gv_samples.py @@ -7,6 +7,7 @@ import traceback import warnings import sys +sys.path.append("/usr/lib/dialcentral") sys.path.append("../../src") import browser_emu @@ -59,7 +60,7 @@ except urllib2.URLError, e: warnings.warn(traceback.format_exc()) raise RuntimeError("%s is not accesible" % gv_backend.GVDialer._loginURL) with open("loggingin.txt", "w") as f: - f.write(page) + f.write(loginSuccessOrFailurePage) forwardPage = browser.download(gv_backend.GVDialer._forwardURL)