From a2962d0970015b5b478b344fb2063f5304cccb59 Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 26 Sep 2014 16:30:37 +0200 Subject: Add logging in conversation module --- client/conversation.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/client/conversation.py b/client/conversation.py index 8ec912c..003a700 100644 --- a/client/conversation.py +++ b/client/conversation.py @@ -1,4 +1,5 @@ # -*- coding: utf-8-*- +import logging from notifier import Notifier from musicmode import * from brain import Brain @@ -8,6 +9,7 @@ from mpd import MPDClient class Conversation(object): def __init__(self, persona, mic, profile): + self._logger = logging.getLogger(__name__) self.persona = persona self.mic = mic self.profile = profile @@ -20,6 +22,7 @@ class Conversation(object): # check if input is meant to start the music module for text in texts: if any(x in text.upper() for x in ["SPOTIFY", "MUSIC"]): + self._logger.debug("Preparing to start music module") # check if mpd client is running try: client = MPDClient() @@ -27,31 +30,41 @@ class Conversation(object): client.idletimeout = None client.connect("localhost", 6600) except: + self._logger.critical("Can't connect to mpd client, cannot start music mode.", exc_info=True) self.mic.say( "I'm sorry. It seems that Spotify is not enabled. Please read the documentation to learn how to configure Spotify.") return - self.mic.say("Please give me a moment, I'm loading your Spotify playlists.") + self._logger.debug("Starting music mode") music_mode = MusicMode(self.persona, self.mic) music_mode.handleForever() + self._logger.debug("Exiting music mode") return self.brain.query(texts) def handleForever(self): """Delegates user input to the handling function when activated.""" + self._logger.info("Starting to handle conversation with keyword '%s'.", self.persona) while True: - # Print notifications until empty notifications = self.notifier.getAllNotifications() for notif in notifications: - print notif + self._logger.info("Got notification: '%s'", str(notif)) + self._logger.debug("Started listening for keyword '%s'", self.persona) threshold, transcribed = self.mic.passiveListen(self.persona) + self._logger.debug("Stopped listening for keyword '%s'", self.persona) + if not transcribed or not threshold: + self._logger.info("Nothing has been said or transcribed.") continue + self._logger.info("Keyword '%s' has been said!", self.persona) + self._logger.debug("Started to listen actively with threshold: %r", threshold) input = self.mic.activeListenToAllOptions(threshold) + self._logger.debug("Stopped to listen actively with threshold: %r", threshold) + if input: self.delegateInput(input) else: -- cgit v1.3.1 From dd32da86b056ba77b78969b5453ba82189150a21 Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 26 Sep 2014 16:31:20 +0200 Subject: Add some logging in notifier module --- client/notifier.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/notifier.py b/client/notifier.py index 6911ed5..434a869 100644 --- a/client/notifier.py +++ b/client/notifier.py @@ -18,12 +18,15 @@ class Notifier(object): self.timestamp = self.gather(self.timestamp) def __init__(self, profile): + self._logger = logging.getLogger(__name__) self.q = Queue.Queue() self.profile = profile self.notifiers = [] if 'gmail_address' in profile and 'gmail_password' in profile: self.notifiers.append(self.NotificationClient(self.handleEmailNotifications, None)) + else: + self._logger.warning('gmail_address or gmail_password not set in profile, Gmail notifier will not be used') sched = Scheduler() sched.start() -- cgit v1.3.1 From 70283a4a64c625d76ebd119e46cd076f643691a6 Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 26 Sep 2014 16:37:00 +0200 Subject: Remove misplaced logging.basicConfig() from notifier.py --- client/notifier.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/notifier.py b/client/notifier.py index 434a869..2ae66f8 100644 --- a/client/notifier.py +++ b/client/notifier.py @@ -3,8 +3,6 @@ import Queue from modules import Gmail from apscheduler.scheduler import Scheduler import logging -logging.basicConfig() - class Notifier(object): -- cgit v1.3.1 From 2939307120af1b8729699f649b354ab2e47637ec Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 26 Sep 2014 16:48:42 +0200 Subject: Improved logging in brain.py --- client/brain.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/client/brain.py b/client/brain.py index 007b7fe..b4620c3 100644 --- a/client/brain.py +++ b/client/brain.py @@ -61,13 +61,15 @@ class Brain(object): """ for module in self.modules: for text in texts: - if module.isValid(text): + self._logger.debug("'%s' is a valid phrase for module '%s'", text, module.__name__) try: module.handle(text, self.mic, self.profile) - return except: self._logger.error('Failed to execute module', exc_info=True) - self.mic.say( - "I'm sorry. I had some trouble with that operation. Please try again later.") + self.mic.say("I'm sorry. I had some trouble with that operation. Please try again later.") + else: + self._logger.debug("Handling of phrase '%s' by module '%s' completed", text, module.__name__) + finally: return + self._logger.debug("No module was able to handle any of these phrases: %r", texts) -- cgit v1.3.1 From ddd893ea290ad57cf78daae4ea4d5ae0793e64c7 Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 26 Sep 2014 19:19:57 +0200 Subject: Configure logging and add possibility to view debug messages in test.py --- client/test.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client/test.py b/client/test.py index 9bd765d..36e5ef5 100644 --- a/client/test.py +++ b/client/test.py @@ -3,6 +3,7 @@ import os import sys import unittest +import logging import argparse from mock import patch, Mock from urllib2 import URLError, urlopen @@ -234,8 +235,15 @@ if __name__ == '__main__': description='Test suite for the Jasper client code.') parser.add_argument('--light', action='store_true', help='runs a subset of the tests (only requires Python dependencies)') + parser.add_argument('--debug', action='store_true', + help='show debug messages') args = parser.parse_args() + logging.basicConfig() + logger = logging.getLogger() + if args.debug: + logger.setLevel(logging.DEBUG) + # Change CWD to jasperpath.LIB_PATH os.chdir(jasperpath.LIB_PATH) -- cgit v1.3.1 From a0a35dcf2159b60e6672eed5c74f238de5f61e4c Mon Sep 17 00:00:00 2001 From: schneefux Date: Tue, 30 Sep 2014 17:29:34 +0200 Subject: Readd missing line in conversation.py --- client/conversation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/client/conversation.py b/client/conversation.py index 003a700..a5b2f8c 100644 --- a/client/conversation.py +++ b/client/conversation.py @@ -35,6 +35,7 @@ class Conversation(object): "I'm sorry. It seems that Spotify is not enabled. Please read the documentation to learn how to configure Spotify.") return + self.mic.say("Please give me a moment, I'm loading your Spotify playlists.") self._logger.debug("Starting music mode") music_mode = MusicMode(self.persona, self.mic) music_mode.handleForever() -- cgit v1.3.1 From 63f4a7c006d54c68a534f0910ed1cb601ed32edb Mon Sep 17 00:00:00 2001 From: schneefux Date: Wed, 1 Oct 2014 13:45:08 +0200 Subject: Change notification log message in conversation.py --- client/conversation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/conversation.py b/client/conversation.py index a5b2f8c..0746b7f 100644 --- a/client/conversation.py +++ b/client/conversation.py @@ -51,7 +51,7 @@ class Conversation(object): # Print notifications until empty notifications = self.notifier.getAllNotifications() for notif in notifications: - self._logger.info("Got notification: '%s'", str(notif)) + self._logger.info("Received notification: '%s'", str(notif)) self._logger.debug("Started listening for keyword '%s'", self.persona) threshold, transcribed = self.mic.passiveListen(self.persona) -- cgit v1.3.1