dbus_service: swap print for logging
authorHelmut Grohne <helmut@subdivi.de>
Sun, 16 Jun 2013 22:02:06 +0000 (00:02 +0200)
committerHelmut Grohne <helmut@subdivi.de>
Sun, 16 Jun 2013 22:02:06 +0000 (00:02 +0200)
dbus_service.py

index f77da7e..41a6546 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
 
+import logging
 import os
 
 import dbus
@@ -9,6 +10,8 @@ from gi.repository import GObject
 
 from onoff.common import ST_ACTIVE, ST_TRANSITION
 
+logger = logging.getLogger("dbus_service")
+
 class OnoffControl(dbus.service.Object):
     domain = "de.subdivi.onoff"
     path = "/de/subdivi/onoff"
@@ -21,7 +24,7 @@ class OnoffControl(dbus.service.Object):
 
     @dbus.service.signal(domain, signature="q")
     def changestate(self, st):
-        print("emitting state %d" % st)
+        logger.debug("emitting state %d", st)
         self.curstate = st
 
     @dbus.service.method(domain, out_signature="q")
@@ -30,16 +33,16 @@ class OnoffControl(dbus.service.Object):
 
     @dbus.service.method(domain, in_signature="q", out_signature="q")
     def activatetime(self, duration):
-        print("called with duration %d" % duration)
+        logger.info("activatetime %d", duration)
         GObject.timeout_add(duration * 1000, self.unuse)
         return self.use()
 
     @dbus.service.method(domain, in_signature="hq", out_signature="q")
     def activatefd(self, fd, duration):
         fd = fd.take()
-        print("called with fd %d and duration %d" % (fd, duration))
+        logger.info("activatefd fd %d, duration %d", (fd, duration))
         def callback(fd, _):
-            print("fd %d completed" % fd)
+            logger.info("fd %d completed", fd)
             os.close(fd)
             GObject.timeout_add(duration * 1000, self.unuse)
             return False
@@ -60,11 +63,13 @@ class OnoffControl(dbus.service.Object):
         if not self.usecount:
             self.changestate(0)
         else:
-            print("%d users left" % self.usecount)
+            logger.debug("%d users left", self.usecount)
         return False
 
 
 def main():
+    logging.basicConfig()
+    logging.getLogger().setLevel(logging.DEBUG)
     DBusGMainLoop(set_as_default=True)
     bus = dbus.SessionBus()
     OnoffControl(bus, 5)