Skip to content

Commit 8aa257e

Browse files
author
geop papa
committed
Bug fixes in logging.
1 parent 8356f4b commit 8aa257e

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/jarvis/jarvis/assistant_utils.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import traceback
44
import logging
5-
import dictconfig
5+
from logging import config
66
from google_speech import Speech
77
from subprocess import call
88

@@ -28,22 +28,22 @@ class OutputStyler:
2828
BOLD = '\033[1m'
2929
UNDERLINE = '\033[4m'
3030

31+
3132
# Create a Console & Rotating file logger
32-
dictconfig.dictConfig(LOG_SETTINGS)
33+
config.dictConfig(LOG_SETTINGS)
34+
3335

3436
def log(func):
3537
def wrapper(*args, **kwargs):
3638
try:
37-
logger.debug(func.__name__)
39+
logging.debug(func.__name__)
3840
func(*args, **kwargs)
3941
except Exception as e:
40-
logger.error(func.__name__)
42+
logging.error(func.__name__)
4143
traceback.print_exc(file=sys.stdout)
4244
return wrapper
43-
return log
4445

4546

46-
@log
4747
def assistant_response(text):
4848
"""
4949
Assistant response in voice or/and in text
@@ -58,7 +58,7 @@ def assistant_response(text):
5858

5959

6060
def user_speech_playback(text):
61-
user_speech = str(OutputStyler.GREEN + 'You: ' + text)
61+
user_speech = str(OutputStyler.GREEN + 'You: ' + text + '\n')
6262
sys.stdout.write(OutputStyler.BLUE + user_speech + OutputStyler.ENDC)
6363

6464

src/jarvis/jarvis/command_manager.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def __init__(self):
2121
self.r = sr.Recognizer()
2222
self.words = None
2323

24+
@log
2425
def run(self):
2526
self.words = self._get_words()
2627
commands = self._get_commands()
@@ -37,7 +38,6 @@ def wake_up_check(self):
3738
self.words = self.r.recognize_google(audio).lower()
3839
except sr.UnknownValueError:
3940
self.words = self._get_words()
40-
4141
if TRIGGERING_WORDS['enable_jarvis'] in self.words:
4242
self._wake_up_response()
4343
return True
@@ -51,6 +51,7 @@ def shutdown_check(self):
5151
"""
5252
if TRIGGERING_WORDS['disable_jarvis'] in self.words:
5353
assistant_response('Bye bye Sir. Have a nice day')
54+
logging.debug('Application terminated gracefully.')
5455
sys.exit()
5556

5657
@staticmethod
@@ -78,6 +79,7 @@ def _get_commands(self):
7879
words_set = set(words)
7980
return commands_set.intersection(words_set)
8081

82+
@log
8183
def _execute_commands(self, commands):
8284
"""
8385
Execute iteratively all the commands in the input dict.
@@ -112,4 +114,5 @@ def _record(self):
112114
self.r.pause_threshold = SPEECH_RECOGNITION['pause_threshold']
113115
self.r.adjust_for_ambient_noise(source, duration=SPEECH_RECOGNITION['ambient_duration'])
114116
audio_text = self.r.listen(source)
117+
115118
return audio_text

src/jarvis/jarvis/settings.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,23 @@
99
'class': 'logging.StreamHandler',
1010
'level': 'INFO',
1111
'formatter': 'detailed',
12-
'stream': 'ext://sys.stdout',
12+
'stream': 'sys.stdout',
1313
},
1414
'file': {
1515
'class': 'logging.handlers.RotatingFileHandler',
16-
'level': 'INFO',
16+
'level': 'DEBUG',
1717
'formatter': 'detailed',
18-
'filename': '/var/logs/jarvis.log',
18+
'filename': '/var/log/jarvis.log',
1919
'mode': 'a',
2020
'maxBytes': 10000000,
2121
'backupCount': 3,
2222
},
2323
},
2424
'formatters': {
2525
'detailed': {
26-
#format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
27-
'format': '%(asctime)s %(module)-17s line:%(lineno)-4d ' \
28-
'%(levelname)-8s %(message)s',
29-
},
26+
'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
27+
},
28+
}
3029
}
3130

3231

0 commit comments

Comments
 (0)