From 010d8596dbe49a9639c639c406bef11964f257d6 Mon Sep 17 00:00:00 2001 From: Travis Gordon Date: Wed, 25 Oct 2023 12:05:38 +0100 Subject: [PATCH 1/8] Added in some of the solution from Gridlington-datahub #98. --- app/__init__.py | 11 +++++++++++ app/log_config.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 app/log_config.py diff --git a/app/__init__.py b/app/__init__.py index a5f5134..32bbc4c 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1 +1,12 @@ """The main module for the Vis system.""" + +import logging +import logging.config + +from .core.log_config import logging_dict_config + +logging.config.dictConfig(logging_dict_config) + +log = logging.getLogger("api_logger") +log.debug("Logging is configured.") +log.info("Datahub API is running...") \ No newline at end of file diff --git a/app/log_config.py b/app/log_config.py new file mode 100644 index 0000000..cc7e478 --- /dev/null +++ b/app/log_config.py @@ -0,0 +1,45 @@ +"""Dict configuration for formal logging.""" +import os + +LOG_LEVEL: str = os.environ.get("API_LOG_LEVEL", "DEBUG") +FORMAT: str = "[%(levelname)s] %(asctime)s | %(message)s" +logging_dict_config = { + "version": 1, + "formatters": { + "default": { + "()": "uvicorn.logging.DefaultFormatter", + "fmt": "%(levelprefix)s %(message)s", + "use_colors": "None", + }, + "basic": { + "()": "uvicorn.logging.DefaultFormatter", + "format": FORMAT, + }, + }, + "handlers": { + "default": { + "formatter": "default", + "class": "logging.StreamHandler", + "stream": "ext://sys.stderr", + }, + "console": { + "formatter": "basic", + "class": "logging.StreamHandler", + "stream": "ext://sys.stderr", + "level": LOG_LEVEL, + }, + "file": { + "level": LOG_LEVEL, + "class": "logging.FileHandler", + "filename": "./log/logging_file.log", + "formatter": "basic", + }, + }, + "loggers": { + "uvicorn": {"handlers": ["default", "file"], "level": "INFO"}, + "api_logger": { + "handlers": ["console", "file"], + "level": LOG_LEVEL, + }, + }, +} \ No newline at end of file From 17e0fe2de0a726469b7aa2d5ce8cccb89ba4eca8 Mon Sep 17 00:00:00 2001 From: tg2414 <56758008+tg2414@users.noreply.github.com> Date: Thu, 2 Nov 2023 12:29:10 +0000 Subject: [PATCH 2/8] Update app/__init__.py Co-authored-by: Adrian D'Alessandro --- app/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/__init__.py b/app/__init__.py index 32bbc4c..05de880 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -3,7 +3,7 @@ import logging import logging.config -from .core.log_config import logging_dict_config +from .log_config import logging_dict_config logging.config.dictConfig(logging_dict_config) From d24e4d37c54a2001305733197ca0079a75a5a424 Mon Sep 17 00:00:00 2001 From: tg2414 <56758008+tg2414@users.noreply.github.com> Date: Thu, 2 Nov 2023 12:29:27 +0000 Subject: [PATCH 3/8] Update app/__init__.py Co-authored-by: Adrian D'Alessandro --- app/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/__init__.py b/app/__init__.py index 05de880..26e3d31 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -9,4 +9,4 @@ log = logging.getLogger("api_logger") log.debug("Logging is configured.") -log.info("Datahub API is running...") \ No newline at end of file +log.info("Gridlington Visualisation System is running...") From aa42560722bffdf91c8eb3ecf7074c06b73945ed Mon Sep 17 00:00:00 2001 From: Travis Gordon Date: Wed, 8 Nov 2023 11:07:02 +0000 Subject: [PATCH 4/8] Changed uvicorn logging to gunicorn and replaced print statements with log statements --- app/log_config.py | 8 +++----- app/pages/control.py | 11 ++++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/log_config.py b/app/log_config.py index cc7e478..8ba1760 100644 --- a/app/log_config.py +++ b/app/log_config.py @@ -7,12 +7,10 @@ "version": 1, "formatters": { "default": { - "()": "uvicorn.logging.DefaultFormatter", "fmt": "%(levelprefix)s %(message)s", "use_colors": "None", }, "basic": { - "()": "uvicorn.logging.DefaultFormatter", "format": FORMAT, }, }, @@ -31,15 +29,15 @@ "file": { "level": LOG_LEVEL, "class": "logging.FileHandler", - "filename": "./log/logging_file.log", + "filename": "./logs/logging_file.log", "formatter": "basic", }, }, "loggers": { - "uvicorn": {"handlers": ["default", "file"], "level": "INFO"}, + "gunicorn": {"handlers": ["default", "file"], "level": "INFO"}, "api_logger": { "handlers": ["console", "file"], "level": LOG_LEVEL, }, }, -} \ No newline at end of file +} diff --git a/app/pages/control.py b/app/pages/control.py index 44f3c77..b3dd5f8 100644 --- a/app/pages/control.py +++ b/app/pages/control.py @@ -6,6 +6,7 @@ from dash_iconify import DashIconify # type: ignore from .. import core_api as core +from .. import log dash.register_page(__name__) @@ -243,7 +244,7 @@ def update_button_click( Args: Value inputs for the 8 dropdown menus """ - print("Clicked Update Button!") + log.debug("Clicked Update Button!") return ["Clicked Update Button!"] elif button_id == "default": @@ -252,22 +253,22 @@ def update_button_click( Args: INIT_SECTIONS list from core_api.py """ - print("Clicked Default Button!") + log.debug("Clicked Default Button!") return ["Clicked Default Button!"] elif button_id == "start": """Will make an API call to start the Gridlington simulation and Datahub.""" - print("Clicked Start Button!") + log.debug("Clicked Start Button!") return ["Clicked Start Button!"] elif button_id == "stop": """Will make an API call to stop the Gridlington simulation and Datahub.""" - print("Clicked Stop Button!") + log.debug("Clicked Stop Button!") return ["Clicked Stop Button!"] elif button_id == "restart": """Will make an API call to restart the Gridlington simulation and Datahub.""" - print("Clicked Restart Button!") + log.debug("Clicked Restart Button!") return ["Clicked Restart Button!"] else: From 808cddf6dd0db592dd5b9354557a1b5f35efeefb Mon Sep 17 00:00:00 2001 From: Travis Gordon Date: Wed, 8 Nov 2023 11:54:32 +0000 Subject: [PATCH 5/8] Added the logs directory to the dash volumes --- docker-compose.yml | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f6ea160 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,49 @@ +services: + dash: + build: . + depends_on: + - nginx + environment: + API_URL: http://192.168.1.252:8080 + DH_URL: http://127.0.0.1 + PLOT_URL: http://192.168.1.252:8050 + ports: + - 8050:8050 + volumes: + - ./app:/app + - ./logs:/logs + nginx: + depends_on: + - ovehub-ove-ove + - ovehub-ove-apps + - ovehub-ove-ui + image: nginx:alpine + ports: + - 8080:8080 + restart: unless-stopped + volumes: + - ./config/default.conf:/etc/nginx/conf.d/default.conf:ro + - ./logs/nginx.log:/etc/nginx/logs/error.log + ovehub-ove-apps: + depends_on: + - ovehub-ove-ove + environment: + OPENVIDU_HOST: https://146.179.34.13:4443 + OPENVIDU_SECRET: MY_SECRET + OVE_HOST: 192.168.1.252:8080 + image: ovehub/ove-apps:0.6.4 + restart: unless-stopped + ovehub-ove-ove: + image: ovehub/ove:0.6.3 + restart: unless-stopped + volumes: + - ./config/Spaces.json:/usr/src/app/packages/ove-core/dist/client/Spaces.json:ro + ovehub-ove-ui: + depends_on: + - ovehub-ove-ove + - ovehub-ove-apps + environment: + OVE_HOST: 192.168.1.252:8080 + image: ovehub/ove-ui:0.2.1 + restart: unless-stopped +version: '3.1' From ab685a034389dfa762bbd7abdee9a32dc5e061fb Mon Sep 17 00:00:00 2001 From: Travis Gordon Date: Wed, 8 Nov 2023 17:19:29 +0000 Subject: [PATCH 6/8] Added the command to build the docker-compose.yml file correctly instead of modifying the .yml file itself. --- configure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.py b/configure.py index 193dfa8..02b5f2d 100755 --- a/configure.py +++ b/configure.py @@ -76,7 +76,7 @@ def generate_docker_compose(template_file: str, ip: str, develop: bool = False) } if develop: docker_compose["services"]["dash"]["build"] = "." - docker_compose["services"]["dash"]["volumes"] = ["./app:/app"] + docker_compose["services"]["dash"]["volumes"] = ["./app:/app", "./logs:/logs"] docker_compose["services"]["dash"]["environment"]["DH_URL"] = "http://127.0.0.1" else: docker_compose["services"]["dash"][ From dfc24ba3c8e0d3b6be5827abf7db1e91a96fbce1 Mon Sep 17 00:00:00 2001 From: Travis Gordon Date: Thu, 9 Nov 2023 13:24:04 +0000 Subject: [PATCH 7/8] Revert "Added the logs directory to the dash volumes" This reverts commit 808cddf6dd0db592dd5b9354557a1b5f35efeefb. --- docker-compose.yml | 49 ---------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index f6ea160..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,49 +0,0 @@ -services: - dash: - build: . - depends_on: - - nginx - environment: - API_URL: http://192.168.1.252:8080 - DH_URL: http://127.0.0.1 - PLOT_URL: http://192.168.1.252:8050 - ports: - - 8050:8050 - volumes: - - ./app:/app - - ./logs:/logs - nginx: - depends_on: - - ovehub-ove-ove - - ovehub-ove-apps - - ovehub-ove-ui - image: nginx:alpine - ports: - - 8080:8080 - restart: unless-stopped - volumes: - - ./config/default.conf:/etc/nginx/conf.d/default.conf:ro - - ./logs/nginx.log:/etc/nginx/logs/error.log - ovehub-ove-apps: - depends_on: - - ovehub-ove-ove - environment: - OPENVIDU_HOST: https://146.179.34.13:4443 - OPENVIDU_SECRET: MY_SECRET - OVE_HOST: 192.168.1.252:8080 - image: ovehub/ove-apps:0.6.4 - restart: unless-stopped - ovehub-ove-ove: - image: ovehub/ove:0.6.3 - restart: unless-stopped - volumes: - - ./config/Spaces.json:/usr/src/app/packages/ove-core/dist/client/Spaces.json:ro - ovehub-ove-ui: - depends_on: - - ovehub-ove-ove - - ovehub-ove-apps - environment: - OVE_HOST: 192.168.1.252:8080 - image: ovehub/ove-ui:0.2.1 - restart: unless-stopped -version: '3.1' From a36772b32b21e014c74b4677bccd0e74954447e3 Mon Sep 17 00:00:00 2001 From: Travis Gordon Date: Thu, 9 Nov 2023 14:37:07 +0000 Subject: [PATCH 8/8] Moved the docker_compose volume into the production version. If in develop version, then the app volume will be added as well --- configure.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/configure.py b/configure.py index 02b5f2d..458569c 100755 --- a/configure.py +++ b/configure.py @@ -74,9 +74,11 @@ def generate_docker_compose(template_file: str, ip: str, develop: bool = False) }, "depends_on": ["nginx"], } + docker_compose["services"]["dash"]["volumes"] = ["./logs:/logs"] + if develop: docker_compose["services"]["dash"]["build"] = "." - docker_compose["services"]["dash"]["volumes"] = ["./app:/app", "./logs:/logs"] + docker_compose["services"]["dash"]["volumes"] += ["./app:/app"] docker_compose["services"]["dash"]["environment"]["DH_URL"] = "http://127.0.0.1" else: docker_compose["services"]["dash"][