From 77f859855c954204e06d8e5ecb9364ffef53c7d9 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Mon, 12 Aug 2024 23:59:41 -0500 Subject: [PATCH] fixed up logging --- conf/apps/apps.yaml | 8 -------- conf/apps/food-repo/src/restaurant/restaurant.py | 2 +- src/ad_test/conftest.py | 8 +++++++- src/ad_test/test_file_change.py | 2 +- src/ad_test/test_startup.py | 5 ++--- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/conf/apps/apps.yaml b/conf/apps/apps.yaml index 6dba59d..4c84034 100644 --- a/conf/apps/apps.yaml +++ b/conf/apps/apps.yaml @@ -1,11 +1,3 @@ hello_world: module: hello class: HelloWorld - -food_app: - module: food - class: Eggs - dependencies: - - hello_world - # class: Ham - # class: Spam \ No newline at end of file diff --git a/conf/apps/food-repo/src/restaurant/restaurant.py b/conf/apps/food-repo/src/restaurant/restaurant.py index faf143e..0fb0d2b 100644 --- a/conf/apps/food-repo/src/restaurant/restaurant.py +++ b/conf/apps/food-repo/src/restaurant/restaurant.py @@ -9,6 +9,6 @@ class Restaurant(ADAPI): self.log(f'{self.__class__.__name__} initialized') self.menu = Menu() - log_str = ', '.join(f'{d.__class__.__name__} [{d.taste}]' for d in self.menu.dishes) + log_str = ', '.join(f'{d.__qualname__} [{d.taste}]' for d in self.menu.dishes) self.log(f'Menu: {log_str}') diff --git a/src/ad_test/conftest.py b/src/ad_test/conftest.py index 3c6b444..f06cedd 100644 --- a/src/ad_test/conftest.py +++ b/src/ad_test/conftest.py @@ -38,6 +38,7 @@ def base_config() -> AppDaemonConfig: time_zone='America/Chicago', config_dir=CONFIG_DIR, config_file='appdaemon.yaml', + module_debug={'_app_management': 'DEBUG'} ) @@ -46,7 +47,12 @@ def ad(base_config: AppDaemonConfig): loop = asyncio.new_event_loop() ad = AppDaemon(Logging(), loop, base_config) - logging.getLogger('AppDaemon').propagate = True + + for cfg in ad.logging.config.values(): + logger = logging.getLogger(cfg['name']) + logger.propagate = True + logger.setLevel('DEBUG') + yield ad ad.stop() diff --git a/src/ad_test/test_file_change.py b/src/ad_test/test_file_change.py index 14c680a..3288330 100644 --- a/src/ad_test/test_file_change.py +++ b/src/ad_test/test_file_change.py @@ -56,7 +56,7 @@ def test_file_with_error(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config insert_import_error(module_file) try: - with caplog.at_level(logging.DEBUG, logger='AppDaemon._app_management'): + with caplog.at_level(logging.DEBUG): ad.loop.run_until_complete(asyncio.sleep(1.0)) module_load_order = get_load_order(caplog) diff --git a/src/ad_test/test_startup.py b/src/ad_test/test_startup.py index 9aea1c3..7fd1399 100644 --- a/src/ad_test/test_startup.py +++ b/src/ad_test/test_startup.py @@ -10,7 +10,7 @@ from .utils import get_load_order def validate_app_dependencies(ad: AppDaemon): graph = ad.app_management.app_config.depedency_graph() - assert 'hello_world' in graph['food_app'] + # assert 'hello_world' in graph['food_app'] def validate_module_dependencies(ad: AppDaemon): @@ -38,8 +38,7 @@ def test_startup(ad: AppDaemon, caplog: pytest.LogCaptureFixture): ad_logger = logging.getLogger('AppDaemon') ad_logger.propagate = True - with caplog.at_level(logging.DEBUG, logger='AppDaemon._app_management'): - # ad_system.loop.run_until_complete(stop_coro) + with caplog.at_level(logging.DEBUG): ad.loop.run_until_complete(asyncio.sleep(2.0)) assert "Started 'hello_world'" in caplog.text