more information in the logfile
authorRalf Jung <post@ralfj.de>
Sat, 1 Mar 2014 15:34:48 +0000 (16:34 +0100)
committerRalf Jung <post@ralfj.de>
Sat, 1 Mar 2014 15:34:48 +0000 (16:34 +0100)
actor.py
libtuer.py
statemachine.py

index f2f1ad28b64cbf02d3ee1a2a6c82abce28f7e830..fb72df73b268a843843e56c2ab9a8ee5ed652e84 100644 (file)
--- a/actor.py
+++ b/actor.py
@@ -12,15 +12,19 @@ class Actor:
        CMD_RED_OFF   = 6
        
        class CMD():
        CMD_RED_OFF   = 6
        
        class CMD():
-               def __init__(self, name, pin, tid, todo):
+               def __init__(self, name, pin, tid, todo, verbose = True):
                        self.name = name
                        self.pin = pin
                        self.tid = tid
                        self.todo = todo
                        self.name = name
                        self.pin = pin
                        self.tid = tid
                        self.todo = todo
+                       self.verbose = verbose
                        # don't do the GPIO setup here, the main init did not yet run
                
                def execute(self):
                        # don't do the GPIO setup here, the main init did not yet run
                
                def execute(self):
-                       logger.info("Actor: Running command %s" % self.name)
+                       if self.verbose:
+                               logger.info("Actor: Running command %s" % self.name)
+                       else:
+                               logger.debug("Actor: Running command %s" % self.name)
                        for (value, delay) in self.todo:
                                if value is not None:
                                        logger.debug("Actor: Setting pin %d to %d" % (self.pin, value))
                        for (value, delay) in self.todo:
                                if value is not None:
                                        logger.debug("Actor: Setting pin %d to %d" % (self.pin, value))
@@ -32,10 +36,10 @@ class Actor:
                CMD_UNLOCK:  CMD("unlock",         pin=12, tid=0, todo=[(True, 0.3), (False, 0.1)]),
                CMD_LOCK:  CMD("lock",             pin=16, tid=0, todo=[(True, 0.3), (False, 0.1)]),
                CMD_BUZZ: CMD("buzz",              pin=22, tid=1, todo=[(True, 2.5), (False, 0.1)]),
                CMD_UNLOCK:  CMD("unlock",         pin=12, tid=0, todo=[(True, 0.3), (False, 0.1)]),
                CMD_LOCK:  CMD("lock",             pin=16, tid=0, todo=[(True, 0.3), (False, 0.1)]),
                CMD_BUZZ: CMD("buzz",              pin=22, tid=1, todo=[(True, 2.5), (False, 0.1)]),
-               CMD_GREEN_ON: CMD("green on",      pin=23, tid=2, todo=[(True, 0)]),
-               CMD_GREEN_OFF: CMD("green off",    pin=23, tid=2, todo=[(False, 0)]),
-               CMD_RED_ON: CMD("red on",          pin=26, tid=2, todo=[(True, 0)]),
-               CMD_RED_OFF: CMD("red off",        pin=26, tid=2, todo=[(False, 0)]),
+               CMD_GREEN_ON: CMD("green on",      pin=23, tid=2, verbose=False, todo=[(True, 0)]),
+               CMD_GREEN_OFF: CMD("green off",    pin=23, tid=2, verbose=False, todo=[(False, 0)]),
+               CMD_RED_ON: CMD("red on",          pin=26, tid=2, verbose=False, todo=[(True, 0)]),
+               CMD_RED_OFF: CMD("red off",        pin=26, tid=2, verbose=False, todo=[(False, 0)]),
        }
        
        def __init__(self):
        }
        
        def __init__(self):
index c9eceec42fa99ae4537563a62002300516485f86..f1e8d54f37780eec00fa2ee2d60bc071d264fcb9 100644 (file)
@@ -63,9 +63,8 @@ def fire_and_forget(f):
        def _fire_and_forget():
                try:
                        f()
        def _fire_and_forget():
                try:
                        f()
-               except Exception as e:
-                       logger.critical("fire_and_forget: Got exception out of callback: %s" % str(e))
-                       logger.debug(traceback.format_exc())
+               except Exception:
+                       logger.critical("fire_and_forget: Got exception out of callback:\n%s" % traceback.format_exc())
        t = threading.Thread(target=_fire_and_forget)
        t.start()
 
        t = threading.Thread(target=_fire_and_forget)
        t.start()
 
@@ -100,8 +99,7 @@ class ThreadFunction():
                                try:
                                        self._f(*data)
                                except Exception as e:
                                try:
                                        self._f(*data)
                                except Exception as e:
-                                       logger.critical("ThreadFunction: Got exception out of handler thread %s: %s" % (self.name, str(e)))
-                                       logger.debug(traceback.format_exc())
+                                       logger.critical("ThreadFunction: Got exception out of handler thread %s:\n%s" % (self.name, traceback.format_exc()))
                        elif cmd == ThreadFunction._TERM:
                                assert data is None
                                break
                        elif cmd == ThreadFunction._TERM:
                                assert data is None
                                break
@@ -139,8 +137,7 @@ class ThreadRepeater():
                        try:
                                self._f()
                        except Exception as e:
                        try:
                                self._f()
                        except Exception as e:
-                               logger.critical("ThreadRepeater: Got exception out of handler thread %s: %s" % (self.name, str(e)))
-                               logger.debug(traceback.format_exc())
+                               logger.critical("ThreadRepeater: Got exception out of handler thread %s:\n%s" % (self.name, traceback.format_exc()))
                        time.sleep(self._sleep_time)
        
        def stop(self):
                        time.sleep(self._sleep_time)
        
        def stop(self):
index dd9dc542bbe51524c24978bc5263bade5b1650de..645737c649f33a1745013de31d3cbfb5c363e1d8 100644 (file)
@@ -380,6 +380,6 @@ class StateMachine():
                while newstate is not None:
                        assert isinstance(newstate, StateMachine.State), "I should get a state"
                        self.current_state.on_leave()
                while newstate is not None:
                        assert isinstance(newstate, StateMachine.State), "I should get a state"
                        self.current_state.on_leave()
-                       logger.debug("StateMachine: Doing state transition %s -> %s" % (self.current_state.__class__.__name__, newstate.__class__.__name__))
+                       logger.info("StateMachine: Doing state transition %s -> %s" % (self.current_state.__class__.__name__, newstate.__class__.__name__))
                        self.current_state = newstate
                        newstate = self.current_state.handle_event(StateMachine.CMD_PINS, self.pins)
                        self.current_state = newstate
                        newstate = self.current_state.handle_event(StateMachine.CMD_PINS, self.pins)