From 0ef8e9b7c6a154f109315a2f597f20f94f65f1b7 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 17 Jan 2013 13:23:02 +0100 Subject: daemon: add some proper loggin support Signed-off-by: Florian Pritz --- daemon.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/daemon.py b/daemon.py index a66c8c5..09210df 100755 --- a/daemon.py +++ b/daemon.py @@ -4,6 +4,11 @@ import serial import mpd import time import sys +import logging + +logger = logging.getLogger() +logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") +logger.setLevel(logging.DEBUG) class Config: display_lines = 2 @@ -30,6 +35,7 @@ class Daemon: self.client = mpd.MPDClient() self.client.connect("localhost", 6600) + logger.debug("connected") def readline(self): return self.ser.readline().decode("ascii").strip() @@ -67,6 +73,8 @@ class Daemon: if self.ser.inWaiting() > 0: incoming = self.readline() + logger.info("got serial command: '%s'", incoming) + functions = { "next": self.client.next, "previous": self.client.previous, @@ -82,6 +90,7 @@ class Daemon: current_position = 0 except KeyError: + logger.warning("ignoring unknown serial command '%s'", incoming) pass # check if song changed @@ -120,7 +129,7 @@ class Daemon: # always start at the beginning if we unpause current_position = 0 - print("'" + buf + "'") + logger.debug("current_position = %s, buf = '%s'", str(current_position).rjust(3), buf) self.ser.write(bytes(buf, "ascii", "replace")) time.sleep(0.05) -- cgit v1.2.3-24-g4f1b