[meld] Introduce some structured logging to replace print()s
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] Introduce some structured logging to replace print()s
- Date: Fri, 30 Nov 2012 19:29:37 +0000 (UTC)
commit 30978f859e6aef34a4b0ae1d915ba9d146c71cb1
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sat Oct 27 11:19:15 2012 +1000
Introduce some structured logging to replace print()s
This commit adds structured logging via Python's logging module,
initialised in meldapp and currently only used by gnomeglade. Logging
is restricted to critical errors if not running uninstalled and from
Git; this is really just an auto-developer switch.
meld/meldapp.py | 17 +++++++++++++++++
meld/ui/gnomeglade.py | 13 ++++++++-----
2 files changed, 25 insertions(+), 5 deletions(-)
---
diff --git a/meld/meldapp.py b/meld/meldapp.py
index 8b6df24..3a18b1b 100644
--- a/meld/meldapp.py
+++ b/meld/meldapp.py
@@ -18,6 +18,7 @@
from __future__ import print_function
+import logging
import optparse
import os
from gettext import gettext as _
@@ -149,6 +150,22 @@ class MeldApp(gobject.GObject):
return new_window
+log = logging.getLogger("meld")
+
+# If we're running uninstalled and from Git, turn up the logging level
+top_level = os.path.dirname(os.path.dirname(__file__))
+if os.path.exists(os.path.join(top_level, "meld.doap")) and \
+ os.path.exists(os.path.join(top_level, ".git")):
+ log.setLevel(logging.WARNING)
+else:
+ log.setLevel(logging.CRITICAL)
+
+handler = logging.StreamHandler()
+formatter = logging.Formatter("%(asctime)s %(levelname)s "
+ "%(name)s: %(message)s")
+handler.setFormatter(formatter)
+log.addHandler(handler)
+
app = MeldApp()
from . import filediff
diff --git a/meld/ui/gnomeglade.py b/meld/ui/gnomeglade.py
index fdd9d95..d7b3f2b 100644
--- a/meld/ui/gnomeglade.py
+++ b/meld/ui/gnomeglade.py
@@ -16,9 +16,11 @@
### Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
### USA.
-import gtk
+import logging
import re
+import gtk
+
# FIXME: duplicate defn in bin/meld
locale_domain = "meld"
@@ -85,6 +87,7 @@ class Component(object):
handler_re = re.compile(r'^(on|after)_(.*)__(.*)$')
def connect_signal_handlers(obj):
+ log = logging.getLogger(__name__)
for attr in dir(obj):
match = handler_re.match(attr)
if match:
@@ -94,7 +97,7 @@ def connect_signal_handlers(obj):
try:
widget = getattr(obj, widgetname)
except AttributeError:
- print "Widget '%s' not found in %s" % (widgetname, obj)
+ log.warning("Widget '%s' not found in %s", widgetname, obj)
continue
if not isinstance(widget,list):
widget = [widget]
@@ -105,13 +108,13 @@ def connect_signal_handlers(obj):
elif when == 'after':
w.connect_after(signal, method)
except TypeError as e:
- print e, "in", obj, attr
+ log.warning("%s in %s %s", e, obj, attr)
elif attr.startswith('on_') or attr.startswith('after_'):
continue # don't warn until all old code updated
# Warn about some possible typos like separating
# widget and signal name with _ instead of __.
- print ('Warning: attribute %r not connected'
- ' as a signal handler' % (attr,))
+ log.warning("Warning: attribute %r not connected as a signal "
+ "handler", attr)
from . import gladesupport
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]