Skip to content

Commit b84ea7d

Browse files
authored
DBC22-4246: Improve huey logging
* DBC22-4246: add huey consumer logging to django configuration * DBC22-4246: improve huey error handling * DBC22-4246: rebase logging config * DBC22-4246: cleanup huey logger
1 parent aace8c8 commit b84ea7d

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ DJANGO_EMAIL_HOST=<smtp host>
2121
DJANGO_EMAIL_PORT=<smtp port>
2222
DJANGO_FROM_EMAIL_DEFAULT=<default from email for all outgoing emails>
2323
DJANGO_FEEDBACK_EMAIL_DEFAULT=<default feedback recipient email>
24+
ROOT_LOG_LEVEL='WARNING'
25+
HUEY_LOG_LEVEL='INFO'
2426

2527
# Django image database connection details
2628
DB_NAME=<database name>

src/backend/apps/webcam/tasks.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from django.db.models import F
2929
from PIL import Image, ImageDraw, ImageFont
3030
from psycopg import IntegrityError
31+
from huey.exceptions import CancelExecution
3132

3233
logger = logging.getLogger(__name__)
3334

@@ -63,7 +64,7 @@ def populate_all_webcam_data():
6364
# Check if the task has timed out at the start of each iteration
6465
if time.time() - start_time > CAMERA_TASK_DEFAULT_TIMEOUT:
6566
logger.warning(f"populate_all_webcam_data stopped: exceeded {CAMERA_TASK_DEFAULT_TIMEOUT} seconds.")
66-
return
67+
raise CancelExecution()
6768

6869
populate_webcam_from_data(webcam_data)
6970

@@ -95,7 +96,7 @@ def update_all_webcam_data():
9596
# Check if the task has timed out at the start of each iteration
9697
if time.time() - start_time > CAMERA_TASK_DEFAULT_TIMEOUT:
9798
logger.warning(f"update_all_webcam_data stopped: exceeded {CAMERA_TASK_DEFAULT_TIMEOUT} seconds.")
98-
return
99+
raise CancelExecution()
99100

100101
current_time = datetime.datetime.now(tz=ZoneInfo("America/Vancouver"))
101102
if camera.should_update(current_time):
@@ -158,6 +159,7 @@ def update_webcam_image(webcam):
158159
base_url = base_url[:-1]
159160
endpoint = f'{base_url}/webcams/{webcam["id"]}/imageSource'
160161

162+
logger.info(f"Requesting GET {endpoint}")
161163
with urllib.request.urlopen(endpoint, timeout=10) as url:
162164
image_data = io.BytesIO(url.read())
163165

@@ -217,7 +219,7 @@ def update_webcam_image(webcam):
217219
delta = mean - stddev
218220

219221
except Exception as e:
220-
logger.info(e)
222+
logger.exception(e)
221223

222224
if lastmod is not None:
223225
delta = datetime.timedelta(seconds=delta)

src/backend/config/settings/django.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,22 +197,34 @@
197197

198198
# Logging
199199
ROOT_LOG_LEVEL = env('ROOT_LOG_LEVEL', default='WARNING')
200+
HUEY_LOG_LEVEL = env('HUEY_LOG_LEVEL', default='INFO')
201+
200202
LOGGING = {
201203
"version": 1,
202204
"disable_existing_loggers": False,
203205
"handlers": {
204206
"console": {
205207
"class": "logging.StreamHandler",
208+
"formatter": 'standard',
206209
},
207210
},
208-
"huey": {
209-
"handlers": ["console"],
210-
"level": ROOT_LOG_LEVEL,
211+
'formatters': {
212+
'standard': {
213+
'class': 'logging.Formatter',
214+
'format': '[%(asctime)s] %(levelname)s:%(name)s:%(threadName)s:%(message)s'
215+
},
211216
},
212-
"django": {
217+
"root": {
213218
"handlers": ["console"],
214219
"level": ROOT_LOG_LEVEL,
215220
},
221+
"loggers": {
222+
"huey": {
223+
"handlers": ["console"],
224+
"level": HUEY_LOG_LEVEL,
225+
"propagate": False
226+
},
227+
},
216228
}
217229

218230
TEST_RUNNER = env("TEST_RUNNER", default="django.test.runner.DiscoverRunner")

0 commit comments

Comments
 (0)