diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-09-24 12:49:20 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2014-09-24 12:49:20 +0200 |
| commit | 48deee55a583ff851ccae0946c90f36cccbc03b8 (patch) | |
| tree | 96393ad7030bdf5e5814c7a5c81a1d248742391b /client | |
| parent | d5c5e9e700e8a906ea089607be53788aad378c5e (diff) | |
| parent | 3468543f0e528115bc28540092d1670c1163537d (diff) | |
| download | jasper-client-48deee55a583ff851ccae0946c90f36cccbc03b8.tar.gz jasper-client-48deee55a583ff851ccae0946c90f36cccbc03b8.zip | |
Merge pull request #179 from Holzhaus/fix-brain-logging
Fix logging in brain.py
Diffstat (limited to 'client')
| -rw-r--r-- | client/brain.py | 14 | ||||
| -rw-r--r-- | client/test.py | 10 |
2 files changed, 7 insertions, 17 deletions
diff --git a/client/brain.py b/client/brain.py index a1fdea4..f197bc4 100644 --- a/client/brain.py +++ b/client/brain.py @@ -5,17 +5,6 @@ import pkgutil import importlib import jasperpath - -def logError(): - logger = logging.getLogger('jasper') - fh = logging.FileHandler('jasper.log') - fh.setLevel(logging.WARNING) - formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') - fh.setFormatter(formatter) - logger.addHandler(fh) - logger.error('Failed to execute module', exc_info=True) - - class Brain(object): def __init__(self, mic, profile): @@ -33,6 +22,7 @@ class Brain(object): self.mic = mic self.profile = profile self.modules = self.get_modules() + self._logger = logging.getLogger(__name__) @classmethod def get_modules(cls): @@ -67,7 +57,7 @@ class Brain(object): module.handle(text, self.mic, self.profile) break except: - logError() + 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.") break diff --git a/client/test.py b/client/test.py index 0160b76..184a777 100644 --- a/client/test.py +++ b/client/test.py @@ -198,15 +198,15 @@ class TestBrain(unittest.TestCase): profile = DEFAULT_PROFILE return brain.Brain(mic, profile) - @patch.object(brain, 'logError') - def testLog(self, logError): + def testLog(self): """Does Brain correctly log errors when raised by modules?""" my_brain = TestBrain._emptyBrain() unclear = my_brain.modules[-1] with patch.object(unclear, 'handle') as mocked_handle: - mocked_handle.side_effect = KeyError('foo') - my_brain.query("zzz gibberish zzz") - logError.assert_called_with() + with patch.object(my_brain._logger, 'error') as mocked_loggingcall: + mocked_handle.side_effect = KeyError('foo') + my_brain.query("zzz gibberish zzz") + self.assertTrue(mocked_loggingcall.called) def testSortByPriority(self): """Does Brain sort modules by priority?""" |
