Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure logging #54

Merged
merged 8 commits into from
Nov 9, 2023
11 changes: 11 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
"""The main module for the Vis system."""

import logging
import logging.config

from .log_config import logging_dict_config

logging.config.dictConfig(logging_dict_config)

log = logging.getLogger("api_logger")
log.debug("Logging is configured.")
log.info("Gridlington Visualisation System is running...")
43 changes: 43 additions & 0 deletions app/log_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""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": {
"fmt": "%(levelprefix)s %(message)s",
"use_colors": "None",
},
"basic": {
"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": "./logs/logging_file.log",
"formatter": "basic",
},
},
"loggers": {
"gunicorn": {"handlers": ["default", "file"], "level": "INFO"},
"api_logger": {
"handlers": ["console", "file"],
"level": LOG_LEVEL,
},
},
}
11 changes: 6 additions & 5 deletions app/pages/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dash_iconify import DashIconify # type: ignore

from .. import core_api as core
from .. import log

dash.register_page(__name__)

Expand Down Expand Up @@ -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":
Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
docker_compose["services"]["dash"]["volumes"] += ["./app:/app"]
docker_compose["services"]["dash"]["environment"]["DH_URL"] = "http://127.0.0.1"
else:
docker_compose["services"]["dash"][
Expand Down