From 46e5a381018b94a14f920b2bd48147d94b448053 Mon Sep 17 00:00:00 2001 From: jarbasai Date: Mon, 10 Oct 2022 14:30:37 +0100 Subject: [PATCH 1/2] feat/xdg_logs bump ovos_utils and make python log to file under XDG_STATE_HOME --- mycroft/audio/__main__.py | 4 ++-- mycroft/client/enclosure/__main__.py | 3 ++- mycroft/client/speech/__main__.py | 3 ++- mycroft/client/text/__main__.py | 2 ++ mycroft/gui/__main__.py | 3 ++- mycroft/listener/__main__.py | 3 ++- mycroft/messagebus/service/__main__.py | 3 ++- mycroft/skills/__main__.py | 3 ++- mycroft/util/__init__.py | 14 ++++++++++++++ mycroft/util/log.py | 1 + requirements/minimal.txt | 2 +- requirements/requirements.txt | 2 +- 12 files changed, 33 insertions(+), 10 deletions(-) diff --git a/mycroft/audio/__main__.py b/mycroft/audio/__main__.py index 00db86b99e46..1c1496c221fa 100644 --- a/mycroft/audio/__main__.py +++ b/mycroft/audio/__main__.py @@ -16,8 +16,7 @@ from ovos_config.locale import setup_locale from mycroft.lock import Lock as PIDLock # Create/Support PID locking file from mycroft.util import reset_sigint_handler, wait_for_exit_signal, \ - check_for_signal - + check_for_signal, init_service_logger service = None # Added for backwards-compat. @@ -25,6 +24,7 @@ def main(ready_hook=on_ready, error_hook=on_error, stopping_hook=on_stopping, watchdog=lambda: None): global service """Start the Audio Service and connect to the Message Bus""" + init_service_logger("audio") reset_sigint_handler() check_for_signal("isSpeaking") PIDLock("audio") diff --git a/mycroft/client/enclosure/__main__.py b/mycroft/client/enclosure/__main__.py index 03a8051cf1f5..a4b90a10bac8 100644 --- a/mycroft/client/enclosure/__main__.py +++ b/mycroft/client/enclosure/__main__.py @@ -8,8 +8,9 @@ to be a drop in replacement for mycroft-core """ - +from mycroft.util import init_service_logger from mycroft.deprecated.enclosure.main import * if __name__ == "__main__": + init_service_logger("enclosure") main() diff --git a/mycroft/client/speech/__main__.py b/mycroft/client/speech/__main__.py index e65cc9c07af4..c593ffdab8a2 100644 --- a/mycroft/client/speech/__main__.py +++ b/mycroft/client/speech/__main__.py @@ -8,12 +8,13 @@ from mycroft.lock import Lock as PIDLock # Create/Support PID locking file from mycroft.util import ( reset_sigint_handler, - wait_for_exit_signal + wait_for_exit_signal, init_service_logger ) def main(ready_hook=on_ready, error_hook=on_error, stopping_hook=on_stopping, watchdog=lambda: None): + init_service_logger("voice") reset_sigint_handler() PIDLock("voice") setup_locale() diff --git a/mycroft/client/text/__main__.py b/mycroft/client/text/__main__.py index 95299068a918..3f6b8a40fa82 100644 --- a/mycroft/client/text/__main__.py +++ b/mycroft/client/text/__main__.py @@ -3,7 +3,9 @@ Text client moved into ovos_cli_client package """ from ovos_cli_client.__main__ import main +from mycroft.util import init_service_logger if __name__ == "__main__": + init_service_logger("cli") main() diff --git a/mycroft/gui/__main__.py b/mycroft/gui/__main__.py index 641f0a051487..15d9a259febc 100644 --- a/mycroft/gui/__main__.py +++ b/mycroft/gui/__main__.py @@ -1,6 +1,6 @@ from ovos_config.locale import setup_locale from mycroft.gui.service import GUIService -from mycroft.util import wait_for_exit_signal, reset_sigint_handler +from mycroft.util import wait_for_exit_signal, reset_sigint_handler, init_service_logger from mycroft.util.log import LOG @@ -17,6 +17,7 @@ def on_error(e='Unknown'): def main(ready_hook=on_ready, error_hook=on_error, stopping_hook=on_stopping): + init_service_logger("gui") LOG.debug("GUI websocket created") try: reset_sigint_handler() diff --git a/mycroft/listener/__main__.py b/mycroft/listener/__main__.py index 647f72cfdbc5..e5afc63a582b 100644 --- a/mycroft/listener/__main__.py +++ b/mycroft/listener/__main__.py @@ -17,12 +17,13 @@ from mycroft.lock import Lock as PIDLock # Create/Support PID locking file from mycroft.util import ( reset_sigint_handler, - wait_for_exit_signal + wait_for_exit_signal, init_service_logger ) def main(ready_hook=on_ready, error_hook=on_error, stopping_hook=on_stopping, watchdog=lambda: None): + init_service_logger("voice") reset_sigint_handler() PIDLock("voice") setup_locale() diff --git a/mycroft/messagebus/service/__main__.py b/mycroft/messagebus/service/__main__.py index 558f18bffc42..a54efe7f6128 100644 --- a/mycroft/messagebus/service/__main__.py +++ b/mycroft/messagebus/service/__main__.py @@ -23,7 +23,7 @@ from mycroft.util import ( reset_sigint_handler, create_daemon, - wait_for_exit_signal + wait_for_exit_signal, init_service_logger ) from mycroft.util.log import LOG from tornado import web, ioloop @@ -42,6 +42,7 @@ def on_stopping(): def main(ready_hook=on_ready, error_hook=on_error, stopping_hook=on_stopping): + init_service_logger("bus") LOG.info('Starting message bus service...') reset_sigint_handler() config = load_message_bus_config() diff --git a/mycroft/skills/__main__.py b/mycroft/skills/__main__.py index 8480db8df0d0..f125cb9112ee 100644 --- a/mycroft/skills/__main__.py +++ b/mycroft/skills/__main__.py @@ -29,7 +29,7 @@ from mycroft.util import ( reset_sigint_handler, start_message_bus_client, - wait_for_exit_signal + wait_for_exit_signal, init_service_logger ) from mycroft.util.log import LOG @@ -44,6 +44,7 @@ def main(alive_hook=on_alive, started_hook=on_started, ready_hook=on_ready, Returns: SkillManager instance or None if it couldn't be initialized """ + init_service_logger("skills") reset_sigint_handler() # Create PID file, prevent multiple instances of this service mycroft.lock.Lock('skills') diff --git a/mycroft/util/__init__.py b/mycroft/util/__init__.py index a68ffd442a6c..975f5c1b0376 100644 --- a/mycroft/util/__init__.py +++ b/mycroft/util/__init__.py @@ -40,3 +40,17 @@ from mycroft.util.signal import check_for_signal, create_signal, \ get_ipc_directory from mycroft.util.platform import get_arch +from ovos_config import Configuration + + +def init_service_logger(service_name): + # this is makes all logs from this service be configured to write to service_name.log file + # if this is not called in every __main__.py entrypoint logs will be written + # to a generic OVOS.log file shared across all services + _cfg = Configuration() + _log_level = _cfg.get("log_level", "INFO") + _logs_conf = _cfg.get("logs") or {} + _logs_conf["level"] = _log_level + LOG.name = service_name + LOG.init(_logs_conf) # read log level from config + diff --git a/mycroft/util/log.py b/mycroft/util/log.py index fc9a82c79e28..3d78bc347af1 100644 --- a/mycroft/util/log.py +++ b/mycroft/util/log.py @@ -6,3 +6,4 @@ def getLogger(name="MYCROFT"): """Depreciated. Use LOG instead""" return LOG + diff --git a/requirements/minimal.txt b/requirements/minimal.txt index 62ae699fb97b..8207d91dabaa 100644 --- a/requirements/minimal.txt +++ b/requirements/minimal.txt @@ -1,7 +1,7 @@ requests~=2.26 mycroft-messagebus-client~=0.9,!=0.9.2,!=0.9.3 combo-lock~=0.2 -ovos-utils~=0.0, >=0.0.23 +ovos-utils~=0.0, >=0.0.25a8 ovos-plugin-manager~=0.0, >=0.0.19a4 ovos-config~=0.0,>=0.0.5a5 python-dateutil~=2.6 diff --git a/requirements/requirements.txt b/requirements/requirements.txt index a35e8e350b9d..9514e02f193c 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -10,7 +10,7 @@ watchdog ovos_backend_client~=0.0, >=0.0.5a3 ovos-config~=0.0,>=0.0.5a5 -ovos-utils~=0.0, >=0.0.23 +ovos-utils~=0.0, >=0.0.25a8 ovos-plugin-manager~=0.0, >=0.0.19a4 ovos-stt-plugin-server~=0.0, >=0.0.2 ovos-tts-plugin-mimic~=0.2, >=0.2.6 From c1963fdda18d7fea2b1d31a2dbc72b1256c7333b Mon Sep 17 00:00:00 2001 From: jarbasai Date: Mon, 10 Oct 2022 16:45:39 +0100 Subject: [PATCH 2/2] no /var/log/mycroft anywhere --- start-bigscreen.sh | 2 +- start-mycroft.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/start-bigscreen.sh b/start-bigscreen.sh index d0132d486414..1c8d7e7cb490 100755 --- a/start-bigscreen.sh +++ b/start-bigscreen.sh @@ -99,7 +99,7 @@ function launch-background() { fi # Launch process in background, sending logs to standard location - python3 -m ${_module} $_params >> /var/log/mycroft/${1}.log 2>&1 & + python3 -m ${_module} $_params & } function launch-all() { diff --git a/start-mycroft.sh b/start-mycroft.sh index b4d55275204d..07cda5092b2a 100755 --- a/start-mycroft.sh +++ b/start-mycroft.sh @@ -97,8 +97,8 @@ function launch-background() { echo "Starting background service $1" fi - # Launch process in background, sending logs to standard location - python3 -m ${_module} $_params >> /var/log/mycroft/${1}.log 2>&1 & + # Launch process in background + python3 -m ${_module} $_params & } function launch-all() {