[mousetrap/gnome3-wip: 98/240] Add logging.
- From: Heidi Ellis <heidiellis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mousetrap/gnome3-wip: 98/240] Add logging.
- Date: Mon, 8 Sep 2014 15:20:48 +0000 (UTC)
commit 56c4b98186c473fd1d38a676fc901fd924671ab9
Author: Stoney Jackson <dr stoney gmail com>
Date: Tue Jun 17 11:06:21 2014 -0400
Add logging.
src/mousetrap/initialize_logging.py | 24 ++++++++++++++++++++++++
src/mousetrap/main.py | 20 +++++++++++++-------
src/mousetrap/pointers/eyes.py | 7 ++++++-
3 files changed, 43 insertions(+), 8 deletions(-)
---
diff --git a/src/mousetrap/initialize_logging.py b/src/mousetrap/initialize_logging.py
new file mode 100644
index 0000000..ad30a55
--- /dev/null
+++ b/src/mousetrap/initialize_logging.py
@@ -0,0 +1,24 @@
+import logging
+
+
+class MouseTrapLoggerInitializer():
+ initialized = False
+
+ @classmethod
+ def initialize(cls):
+ if not cls.initialized:
+ cls._initialize_logger()
+ cls.initialized = True
+
+ @classmethod
+ def _initialize_logger(cls):
+ app_logger = logging.getLogger('mousetrap')
+ app_logger.setLevel(logging.DEBUG)
+ handler = logging.StreamHandler()
+ handler.setLevel(logging.DEBUG)
+ formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+ handler.setFormatter(formatter)
+ app_logger.addHandler(handler)
+
+
+MouseTrapLoggerInitializer.initialize()
diff --git a/src/mousetrap/main.py b/src/mousetrap/main.py
index 7183ccc..9147cd7 100644
--- a/src/mousetrap/main.py
+++ b/src/mousetrap/main.py
@@ -2,7 +2,10 @@
Where it all begins.
'''
-from datetime import datetime
+# NOTE: import this first to set up logging properly.
+import mousetrap.initialize_logging
+
+import logging
from gi.repository import GObject, Gdk, Gtk
from mousetrap.vision import Camera
from mousetrap.gui import ScreenPointer, Gui
@@ -10,11 +13,14 @@ from mousetrap.pointers.nose_joystick import Pointer
from mousetrap.pointers.eyes import Pointer as Eyes
-FPS = 10
-INTERVAL = int(round(1000.0 / FPS))
+LOGGER = logging.getLogger('mousetrap.main')
class Main(object):
+
+ FPS = 10
+ INTERVAL = int(round(1000.0 / FPS))
+
def __init__(self):
self.timeout_id = None
self.camera = Camera()
@@ -25,7 +31,7 @@ class Main(object):
self.eyes = Eyes()
def run(self):
- self.timeout_id = GObject.timeout_add(INTERVAL, self.on_timeout, None)
+ self.timeout_id = GObject.timeout_add(self.INTERVAL, self.on_timeout, None)
self.gui.start()
def on_timeout(self, user_data):
@@ -41,7 +47,7 @@ class Main(object):
if position is not None:
return True
- print str(datetime.now()) + ': No change.'
+ LOGGER.debug('No change.')
self.eyes.update_image(image)
keys = self.eyes.get_keys()
@@ -49,12 +55,12 @@ class Main(object):
if keys is None:
return True
- print keys.get_actions()
+ LOGGER.debug(keys.get_actions())
display = Display()
for action in keys.get_actions():
- print action.event, action.button
+ LOGGER.debug('%s %s', action.event, action.button)
xtest.fake_input(display, action.event, action.button)
display.sync()
diff --git a/src/mousetrap/pointers/eyes.py b/src/mousetrap/pointers/eyes.py
index eb8cc07..f79099f 100644
--- a/src/mousetrap/pointers/eyes.py
+++ b/src/mousetrap/pointers/eyes.py
@@ -1,9 +1,14 @@
import mousetrap.pointers.interface as interface
from mousetrap.vision import FeatureDetector, FeatureNotFoundException
+import logging
+
+
+LOGGER = logging.getLogger(__name__)
class Pointer(interface.Pointer):
def __init__(self):
+
self._left_locator = LeftEyeLocator()
self._history = []
@@ -67,7 +72,7 @@ class LeftEyeLocator(object):
face = self._face_detector.detect(image)
eye = self._eye_detector.detect(face["image"])
- print eye
+ LOGGER.debug(eye)
return (0, 0)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]