[mousetrap/gnome3-wip: 185/240] Change default logging to INFO, and add INFO messages.



commit b54a0013de96afbccf104664bf7cd9bfc9605d28
Author: Stoney Jackson <dr stoney gmail com>
Date:   Fri Jun 27 21:18:38 2014 -0400

    Change default logging to INFO, and add INFO messages.
    
    DEBUG
    * Provides details useful for debugging.
    * May be voluminous.
    * Performance isn't a concern.
    * Information is not typically useful to the user.
    
    INFO
    * Provides indication of status.
    * Should not impede performance.
    * Information is typically useful to the user.
    
    In general, use DEBUG for large, frequent, detailed messages and for
    messages that the user probably does not need to know. Use INFO for
    smaller, less frequent, less detailed messages that the user probably
    should know.

 src/mousetrap/config.py                          |    2 +-
 src/mousetrap/locale/en/LC_MESSAGES/mousetrap.po |    2 +-
 src/mousetrap/main.py                            |    3 ++-
 src/mousetrap/mousetrap.yaml                     |    2 +-
 src/mousetrap/vision.py                          |   13 ++++++++++++-
 5 files changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/src/mousetrap/config.py b/src/mousetrap/config.py
index ee99a22..bcbdc52 100644
--- a/src/mousetrap/config.py
+++ b/src/mousetrap/config.py
@@ -25,7 +25,7 @@ class Config(dict):
     def _load(self):
         for name, path in self.SEARCH_PATH.items():
             if isfile(path):
-                print("loading %s" % (path))
+                print("Loading %s" % (path))
                 with open(path) as config_file:
                     config = safe_load(config_file)
                     _rmerge(self, config)
diff --git a/src/mousetrap/locale/en/LC_MESSAGES/mousetrap.po 
b/src/mousetrap/locale/en/LC_MESSAGES/mousetrap.po
index 4d2cb9e..ffea527 100644
--- a/src/mousetrap/locale/en/LC_MESSAGES/mousetrap.po
+++ b/src/mousetrap/locale/en/LC_MESSAGES/mousetrap.po
@@ -7,7 +7,7 @@ msgstr ""
 "Project-Id-Version: MouseTrap master\n"
 "Report-Msgid-Bugs-To: http://bugzilla.gnome.org/enter_bug.cgi?";
 "product=mousetrap&keywords=I18N+L10N&component=i18n\n"
-"POT-Creation-Date: 2014-06-25 20:58-0400\n"
+"POT-Creation-Date: 2014-06-27 20:11-0400\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: MouseTrap team\n"
 "Language-Team: English <en li org>\n"
diff --git a/src/mousetrap/main.py b/src/mousetrap/main.py
index ed2eb4a..04c9305 100644
--- a/src/mousetrap/main.py
+++ b/src/mousetrap/main.py
@@ -23,6 +23,7 @@ from mousetrap.vision import Camera
 
 class App(object):
     def __init__(self, config):
+        LOGGER.info("Initializing")
         self.config = config
         self.image = None
         self.loop = Loop(config, self)
@@ -42,7 +43,7 @@ class App(object):
 
     def _load_plugin(self, class_):
         try:
-            LOGGER.debug('loading %s', class_)
+            LOGGER.info('loading %s', class_)
             class_path = class_.split('.')
             module = __import__('.'.join(class_path[:-1]), {}, {}, class_path[-1])
             return getattr(module, class_path[-1])(self.config)
diff --git a/src/mousetrap/mousetrap.yaml b/src/mousetrap/mousetrap.yaml
index 3110c4f..fb2bb60 100644
--- a/src/mousetrap/mousetrap.yaml
+++ b/src/mousetrap/mousetrap.yaml
@@ -47,7 +47,7 @@ logging:
     console:
       class: logging.StreamHandler
       formatter: default
-      level: DEBUG
+      level: INFO
       stream: ext://sys.stdout
   root:
     formatters:
diff --git a/src/mousetrap/vision.py b/src/mousetrap/vision.py
index 601742c..0957f4f 100644
--- a/src/mousetrap/vision.py
+++ b/src/mousetrap/vision.py
@@ -7,6 +7,8 @@ import cv
 from mousetrap.i18n import _
 from mousetrap.image import Image
 
+import logging
+LOGGER = logging.getLogger(__name__)
 
 class Camera(object):
     S_CAPTURE_OPEN_ERROR = _('Device #%d does not support video capture interface')
@@ -103,6 +105,7 @@ class FeatureDetector(object):
         self._cascade = HaarLoader(config).from_name(name)
         self._scale_factor = scale_factor
         self._min_neighbors = min_neighbors
+        self._last_attempt_successful = False
 
     def detect(self, image):
         self._image = image
@@ -122,7 +125,15 @@ class FeatureDetector(object):
 
     def _exit_if_none_detected(self):
         if len(self._plural) == 0:
-            raise FeatureNotFoundException(_('Feature not detected: %s') % (self._name))
+            message = _('Feature not detected: %s') % (self._name)
+            if self._last_attempt_successful:
+                self._last_attempt_successful = False
+                LOGGER.info(message)
+            raise FeatureNotFoundException(message)
+        else:
+            if not self._last_attempt_successful:
+                self._last_attempt_successful = True
+                LOGGER.info(_('Feature detected: %s') % (self._name))
 
     def _unpack_first(self):
         self._single = dict(zip(['x', 'y', 'width', 'height'], self._plural[0]))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]