diff --git a/.gitignore b/.gitignore index 973c3c1..cf30e27 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /.vscode/ /src/media/ /src/staticfiles/ +*log *.mo *.pyc htmlcov/ diff --git a/docker-compose.yaml b/docker-compose.yaml index da46d48..419a0b9 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -49,7 +49,7 @@ services: restart: always ports: - "6379:6379" - + # Production service - "service", "image", and "container_name" should all contain the same # reference, based on the name of the service. sdnginx: diff --git a/src/signal_documentation/settings.py b/src/signal_documentation/settings.py index ad66194..6155d88 100644 --- a/src/signal_documentation/settings.py +++ b/src/signal_documentation/settings.py @@ -10,6 +10,8 @@ https://docs.djangoproject.com/en/4.2/ref/settings/ """ import os +import sys +from distutils.util import strtobool from pathlib import Path from typing import Any @@ -43,7 +45,7 @@ # SECURITY WARNING: don't run with debug turned on in production! -DEBUG: bool = True +DEBUG = bool(strtobool(os.getenv('DEBUG', 'True'))) # SECURITY WARNING: keep the secret key used in production secret! @@ -158,7 +160,7 @@ } -PAGE_SIZE = os.environ.get('PAGE_SIZE', 10) +PAGE_SIZE: int = int(os.environ.get('PAGE_SIZE', 10)) CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5" @@ -189,6 +191,38 @@ ), } +# Logging +# https://docs.djangoproject.com/en/4.2/topics/logging/ + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'formatters': { + 'simple': { + 'format': '[%(asctime)s] %(levelname)s | %(name)s | %(message)s', + 'datefmt': '%Y-%m-%d %H:%M:%S', + }, + }, + 'handlers': { + 'console': { + 'class': 'logging.StreamHandler', + 'formatter': 'simple', + 'stream': sys.stdout, + }, + }, + 'loggers': { + 'django': { + 'handlers': ['console'], + 'level': 'INFO', + 'propagate': True, + }, + }, +} + +if DEBUG: + for logger in LOGGING['loggers']: + LOGGING['loggers'][logger]['handlers'] = ['console'] + # DRF Spectacular settings # https://drf-spectacular.readthedocs.io/en/latest/settings.html diff --git a/src/signals/tools.py b/src/signals/tools.py index 2fe1e00..5fc4485 100644 --- a/src/signals/tools.py +++ b/src/signals/tools.py @@ -1,7 +1,10 @@ +import logging from datetime import datetime from signals.models import Signal +logger = logging.getLogger('default') + class SignalLastUpdatedParser: @@ -33,9 +36,12 @@ def set_data(self) -> None: try: signal = Signal.objects.get(name=signal_data['signal_basename'], source__name=signal_data['source']) except Signal.DoesNotExist: - # TODO: Log this + logger.warning( + f"Signal {signal_data['signal_basename']} not found in db. Update failed." + ) continue signal.last_updated = self.format_date(str(signal_data['max_issue'])) signal.from_date = self.format_date(str(signal_data['min_time'])) signal.to_date = self.format_date(str(signal_data['max_time'])) signal.save() + logger.info(f"Signal {signal_data['signal_basename']} successfully updated.")