From acf6864b7f168771198d1774799129c3d79b437a Mon Sep 17 00:00:00 2001 From: Shankari Date: Sun, 6 Oct 2024 12:13:34 -0700 Subject: [PATCH] Fix logging so we can see what happens in the remind case We check to see if a user has valid trips in the past 7 days before we send them a reminder (https://github.com/e-mission/e-mission-server/commit/70344796f16ecc84db2e1e4eccd8b718e473e357). However, all the related messages are displayed using `logging.debug`. Because of the additional imports, logging is configured to WARNING, so they are never displayed. And in the case where there are no users with recent trips, this results in insufficient logging to determine what happened. - Changing the logging configuration location - Changing the log level to INFO - Bumping up some useful logs to INFO Testing done: Before the change ``` Found configuration, overriding... Activating the environment... Run trip labeling reminder... Config file not found, returning a copy of the environment variables instead... Retrieved config: {'DB_HOST': '...', 'DB_RESULT_LIMIT': None} Connecting to database URL ... WARNING:root:Push configured for app .... using platform firebase with token ... of length 152 ``` After the change ``` Found configuration, overriding... Activating the environment... Run trip labeling reminder... Config file not found, returning a copy of the environment variables instead... Retrieved config: {'DB_HOST': '...', 'DB_RESULT_LIMIT': None} Connecting to database URL ... WARNING:root:Push configured for app ... using platform firebase with token ... of length 152 INFO:root:Successfully downloaded config with version 1 for Staging environment for testing programs only and data collection URL https://openpath-stage.nrel.gov/api/ INFO:root:No users to notify in lang en ``` --- bin/push/push_remind.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/push/push_remind.py b/bin/push/push_remind.py index 6182757b5..376bbd417 100644 --- a/bin/push/push_remind.py +++ b/bin/push/push_remind.py @@ -1,6 +1,7 @@ import arrow import json import logging +logging.basicConfig(level=logging.INFO) import os import requests import sys @@ -55,7 +56,6 @@ def bin_users_by_lang(uuid_list, langs, lang_key='phone_lang'): if __name__ == '__main__': - logging.basicConfig(level=logging.DEBUG) logging.debug(f"STUDY_CONFIG is {STUDY_CONFIG}") STUDY_CONFIG = os.getenv('STUDY_CONFIG', "stage-study") @@ -68,12 +68,12 @@ def bin_users_by_lang(uuid_list, langs, lang_key='phone_lang'): sys.exit(1) dynamic_config = json.loads(r.text) - logging.debug(f"Successfully downloaded config with version {dynamic_config['version']} "\ + logging.info(f"Successfully downloaded config with version {dynamic_config['version']} "\ f"for {dynamic_config['intro']['translated_text']['en']['deployment_name']} "\ f"and data collection URL {dynamic_config['server']['connectUrl']}") if "reminderSchemes" in dynamic_config: - logging.debug("Found flexible notification configuration, skipping server-side push") + logging.info("Found flexible notification configuration, skipping server-side push") sys.exit(0) # get push notification config (if not present in dynamic_config, use default) @@ -99,9 +99,9 @@ def bin_users_by_lang(uuid_list, langs, lang_key='phone_lang'): # for each language, send a push notification to the selected users in that language for lang, uuids_to_notify in filtered_uuids_by_lang.items(): if len(uuids_to_notify) == 0: - logging.debug(f"No users to notify in lang {lang}") + logging.info(f"No users to notify in lang {lang}") continue - logging.debug(f"Sending push notifications to {len(uuids_to_notify)} users in lang {lang}") + logging.info(f"Sending push notifications to {len(uuids_to_notify)} users in lang {lang}") json_data = { "title": push_config["title"][lang], "message": push_config["message"][lang],