Skip to content

Commit ec4e604

Browse files
authored
Merge pull request #97 from cmu-delphi/OKRS24-140-Setup-logging
added logging
2 parents 4cfe801 + 35fd24f commit ec4e604

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/.vscode/
44
/src/media/
55
/src/staticfiles/
6+
*log
67
*.mo
78
*.pyc
89
htmlcov/

docker-compose.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ services:
4949
restart: always
5050
ports:
5151
- "6379:6379"
52-
52+
5353
# Production service - "service", "image", and "container_name" should all contain the same
5454
# reference, based on the name of the service.
5555
sdnginx:

src/signal_documentation/settings.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
https://docs.djangoproject.com/en/4.2/ref/settings/
1111
"""
1212
import os
13+
import sys
14+
from distutils.util import strtobool
1315
from pathlib import Path
1416
from typing import Any
1517

@@ -43,7 +45,7 @@
4345

4446

4547
# SECURITY WARNING: don't run with debug turned on in production!
46-
DEBUG: bool = True
48+
DEBUG = bool(strtobool(os.getenv('DEBUG', 'True')))
4749

4850

4951
# SECURITY WARNING: keep the secret key used in production secret!
@@ -187,6 +189,38 @@
187189
),
188190
}
189191

192+
# Logging
193+
# https://docs.djangoproject.com/en/4.2/topics/logging/
194+
195+
LOGGING = {
196+
'version': 1,
197+
'disable_existing_loggers': False,
198+
'formatters': {
199+
'simple': {
200+
'format': '[%(asctime)s] %(levelname)s | %(name)s | %(message)s',
201+
'datefmt': '%Y-%m-%d %H:%M:%S',
202+
},
203+
},
204+
'handlers': {
205+
'console': {
206+
'class': 'logging.StreamHandler',
207+
'formatter': 'simple',
208+
'stream': sys.stdout,
209+
},
210+
},
211+
'loggers': {
212+
'django': {
213+
'handlers': ['console'],
214+
'level': 'INFO',
215+
'propagate': True,
216+
},
217+
},
218+
}
219+
220+
if DEBUG:
221+
for logger in LOGGING['loggers']:
222+
LOGGING['loggers'][logger]['handlers'] = ['console']
223+
190224

191225
# DRF Spectacular settings
192226
# https://drf-spectacular.readthedocs.io/en/latest/settings.html

src/signals/tools.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import logging
12
from datetime import datetime
23

34
from signals.models import Signal
45

6+
logger = logging.getLogger('default')
7+
58

69
class SignalLastUpdatedParser:
710

@@ -35,9 +38,12 @@ def set_data(self) -> None:
3538
try:
3639
signal = Signal.objects.get(name=signal_data['signal_basename'], source__name=signal_data['source'])
3740
except Signal.DoesNotExist:
38-
# TODO: Log this
41+
logger.warning(
42+
f"Signal {signal_data['signal_basename']} not found in db. Update failed."
43+
)
3944
continue
4045
signal.last_updated = self.format_date(str(signal_data['max_issue']))
4146
signal.from_date = self.format_date(str(signal_data['min_time']))
4247
signal.to_date = self.format_date(str(signal_data['max_time']))
4348
signal.save()
49+
logger.info(f"Signal {signal_data['signal_basename']} successfully updated.")

0 commit comments

Comments
 (0)