diff --git a/app/aws/s3.py b/app/aws/s3.py index 38845c0bd..42edee1a6 100644 --- a/app/aws/s3.py +++ b/app/aws/s3.py @@ -647,7 +647,7 @@ def s3upload( metadata = put_args["Metadata"] = metadata try: - current_app.logger.info(hilite(f"Going to try to upload this {key}")) + current_app.logger.debug(hilite(f"Going to try to upload this {key}")) key.put(**put_args) except botocore.exceptions.NoCredentialsError as e: current_app.logger.exception( diff --git a/app/celery/research_mode_tasks.py b/app/celery/research_mode_tasks.py index 58f34c6a6..2f82e520b 100644 --- a/app/celery/research_mode_tasks.py +++ b/app/celery/research_mode_tasks.py @@ -51,7 +51,7 @@ def make_request(notification_type, provider, data, headers): ) raise e finally: - current_app.logger.info("Mocked provider callback request finished") + current_app.logger.debug("Mocked provider callback request finished") return response.json() diff --git a/app/celery/scheduled_tasks.py b/app/celery/scheduled_tasks.py index 709994910..05d4f72a7 100644 --- a/app/celery/scheduled_tasks.py +++ b/app/celery/scheduled_tasks.py @@ -304,14 +304,6 @@ def cleanup_delivery_receipts(self): def batch_insert_notifications(self): batch = [] - # TODO We probably need some way to clear the list if - # things go haywire. A command? - - # with redis_store.pipeline(): - # while redis_store.llen("message_queue") > 0: - # redis_store.lpop("message_queue") - # current_app.logger.info("EMPTY!") - # return current_len = redis_store.llen("message_queue") with redis_store.pipeline(): # since this list is being fed by other processes, just grab what is available when diff --git a/app/celery/test_key_tasks.py b/app/celery/test_key_tasks.py index f18976a5f..d11f40982 100644 --- a/app/celery/test_key_tasks.py +++ b/app/celery/test_key_tasks.py @@ -51,7 +51,7 @@ def make_request(notification_type, provider, data, headers): ) raise e finally: - current_app.logger.info("Mocked provider callback request finished") + current_app.logger.debug("Mocked provider callback request finished") return response.json() diff --git a/app/commands.py b/app/commands.py index 020b0610d..53cda2fdf 100644 --- a/app/commands.py +++ b/app/commands.py @@ -183,7 +183,7 @@ def insert_inbound_numbers_from_file(file_name): for line in file: line = line.strip() if line: - current_app.logger.info(line) + current_app.logger.debug(line) db.session.execute(sql, {"uuid": str(uuid.uuid4()), "line": line}) db.session.commit() @@ -228,7 +228,6 @@ def bulk_invite_user_to_service(file_name, service_id, user_id, auth_type, permi # "send_texts,send_emails,view_activity" from app.service_invite.rest import create_invited_user - current_app.logger.info("ENTER") file = open(file_name) for email_address in file: data = { @@ -239,7 +238,6 @@ def bulk_invite_user_to_service(file_name, service_id, user_id, auth_type, permi "auth_type": auth_type, "invite_link_host": current_app.config["ADMIN_BASE_URL"], } - current_app.logger.info(f"DATA = {data}") with current_app.test_request_context( path=f"/service/{service_id}/invite/", method="POST", @@ -248,12 +246,12 @@ def bulk_invite_user_to_service(file_name, service_id, user_id, auth_type, permi ): try: response = create_invited_user(service_id) - current_app.logger.info(f"RESPONSE {response[1]}") + current_app.logger.debug(f"RESPONSE {response[1]}") if response[1] != 201: current_app.logger.warning( f"*** ERROR occurred for email address: {email_address.strip()}" ) - current_app.logger.info(response[0].get_data(as_text=True)) + current_app.logger.debug(response[0].get_data(as_text=True)) except Exception: current_app.logger.exception( f"*** ERROR occurred for email address: {email_address.strip()}.", @@ -337,7 +335,6 @@ def populate_organizations_from_file(file_name): for line in itertools.islice(f, 1, None): columns = line.split("|") - current_app.logger.info(columns) email_branding = None email_branding_column = columns[5].strip() if len(email_branding_column) > 0: @@ -439,20 +436,19 @@ def populate_go_live(file_name): # 6- Contact detail, 7-MOU, 8- LIVE date, 9- SMS, 10 - Email, 11 - Letters, 12 -CRM, 13 - Blue badge import csv - current_app.logger.info("Populate go live user and date") with open(file_name, "r") as f: rows = csv.reader( f, quoting=csv.QUOTE_MINIMAL, skipinitialspace=True, ) - current_app.logger.info(next(rows)) # ignore header row + current_app.logger.debug(next(rows)) # ignore header row for index, row in enumerate(rows): - current_app.logger.info(index, row) + current_app.logger.debug(index, row) service_id = row[2] go_live_email = row[6] go_live_date = datetime.strptime(row[8], "%d/%m/%Y") + timedelta(hours=12) - current_app.logger.info(service_id, go_live_email, go_live_date) + current_app.logger.debug(service_id, go_live_email, go_live_date) try: if go_live_email: go_live_user = get_user_by_email(go_live_email) @@ -506,13 +502,11 @@ def fix_billable_units(): ) db.session.execute(stmt) db.session.commit() - current_app.logger.info("End fix_billable_units") @notify_command(name="delete-unfinished-jobs") def delete_unfinished_jobs(): cleanup_unfinished_jobs() - current_app.logger.info("End cleanup_unfinished_jobs") @notify_command(name="process-row-from-job") @@ -618,7 +612,7 @@ def dump_user_info(user_email_address): with open("user_download.json", "wb") as f: f.write(json.dumps(content).encode("utf8")) f.close() - current_app.logger.info("Successfully downloaded user info to user_download.json") + current_app.logger.debug("Successfully downloaded user info to user_download.json") @notify_command(name="populate-annual-billing-with-defaults") diff --git a/app/errors.py b/app/errors.py index 41c760da6..10f88eac5 100644 --- a/app/errors.py +++ b/app/errors.py @@ -49,24 +49,24 @@ def register_errors(blueprint): @blueprint.errorhandler(ValidationError) def marshmallow_validation_error(error): - current_app.logger.info(error) + current_app.logger.error(error, exc_info=True) return jsonify(result="error", message=error.messages), 400 @blueprint.errorhandler(JsonSchemaValidationError) def jsonschema_validation_error(error): - current_app.logger.info(error) + current_app.logger.error(error, exc_info=True) return jsonify(json.loads(error.message)), 400 @blueprint.errorhandler(ArchiveValidationError) def archive_validation_error(error): - current_app.logger.info(error) + current_app.logger.error(error, exc_info=True) return jsonify(result="error", message=str(error)), 400 @blueprint.errorhandler(InvalidRequest) def invalid_data(error): response = jsonify(error.to_dict()) response.status_code = error.status_code - current_app.logger.info(error) + current_app.logger.error(error, exc_info=True) return response @blueprint.errorhandler(400) diff --git a/app/service/rest.py b/app/service/rest.py index a708c51de..766918f1e 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -219,7 +219,7 @@ def get_service_by_id(service_id): data = service_schema.dump(fetched) - current_app.logger.info(f'>> SERVICE: {data["id"]}; {data}') + current_app.logger.debug(f'>> SERVICE: {data["id"]}; {data}') return jsonify(data=data) diff --git a/app/user/rest.py b/app/user/rest.py index 867513238..defddf551 100644 --- a/app/user/rest.py +++ b/app/user/rest.py @@ -455,8 +455,6 @@ def send_new_user_email_verification(user_id): ) service = db.session.get(Service, current_app.config["NOTIFY_SERVICE_ID"]) - current_app.logger.info("template.id is {}".format(template.id)) - current_app.logger.info("service.id is {}".format(service.id)) personalisation = { "name": user_to_send_to.name, "url": _create_verification_url( @@ -487,11 +485,11 @@ def send_new_user_email_verification(user_id): json.dumps(personalisation), ex=60 * 60, ) - current_app.logger.info("Sending notification to queue") + current_app.logger.debug("Sending notification to queue") send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY) - current_app.logger.info("Sent notification to queue") + current_app.logger.debug("Sent notification to queue") return jsonify({}), 204 @@ -499,18 +497,16 @@ def send_new_user_email_verification(user_id): @user_blueprint.route("//email-already-registered", methods=["POST"]) def send_already_registered_email(user_id): check_suspicious_id(user_id) - current_app.logger.info("Email already registered for user {}".format(user_id)) + current_app.logger.debug("Email already registered for user {}".format(user_id)) to = email_data_request_schema.load(request.get_json()) - current_app.logger.info("To email is {}".format(to["email"])) + current_app.logger.debug("To email is {}".format(to["email"])) template = dao_get_template_by_id( current_app.config["ALREADY_REGISTERED_EMAIL_TEMPLATE_ID"] ) service = db.session.get(Service, current_app.config["NOTIFY_SERVICE_ID"]) - current_app.logger.info("template.id is {}".format(template.id)) - current_app.logger.info("service.id is {}".format(service.id)) personalisation = { "signin_url": current_app.config["ADMIN_BASE_URL"] + "/sign-in", "forgot_password_url": current_app.config["ADMIN_BASE_URL"] @@ -530,8 +526,6 @@ def send_already_registered_email(user_id): ) saved_notification.personalisation = personalisation - current_app.logger.info("Sending notification to queue") - redis_store.set( f"email-personalisation-{saved_notification.id}", json.dumps(personalisation), @@ -540,8 +534,6 @@ def send_already_registered_email(user_id): send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY) - current_app.logger.info("Sent notification to queue") - return jsonify({}), 204 @@ -612,7 +604,7 @@ def get_user_login_gov_user(): if user is None: current_app.logger.info("#invites: couldn't find user, returning empty data") return jsonify({}) - current_app.logger.info("#invites: found the user, serializing") + current_app.logger.debug("#invites: found the user, serializing") result = user.serialize() current_app.logger.info("#invites: returning successfully") return jsonify(data=result) diff --git a/notifications_python_client/base.py b/notifications_python_client/base.py index ba6038fa6..34c8d6667 100644 --- a/notifications_python_client/base.py +++ b/notifications_python_client/base.py @@ -2,7 +2,6 @@ import json import logging import time import urllib.parse - from os import getenv import requests diff --git a/notifications_utils/clients/redis/redis_client.py b/notifications_utils/clients/redis/redis_client.py index b7669773c..5ec97ac09 100644 --- a/notifications_utils/clients/redis/redis_client.py +++ b/notifications_utils/clients/redis/redis_client.py @@ -80,7 +80,9 @@ class RedisClient: try: return self.scripts["delete-keys-by-pattern"](args=[pattern]) except Exception as e: - current_app.logger.exception(f"Exception in delete_by_pattern pattern={pattern}") + current_app.logger.exception( + f"Exception in delete_by_pattern pattern={pattern}" + ) self.__handle_exception( e, raise_exception, "delete-by-pattern", pattern ) @@ -130,7 +132,9 @@ class RedisClient: result = pipe.execute() return result[2] > limit except Exception as e: - current_app.logger.exception(f"Exception in exceeded_rate_limit cache_key {cache_key} limit = {limit}") + current_app.logger.exception( + f"Exception in exceeded_rate_limit cache_key {cache_key} limit = {limit}" + ) self.__handle_exception( e, raise_exception, "rate-limit-pipeline", cache_key ) diff --git a/notifications_utils/recipients.py b/notifications_utils/recipients.py index d41419064..e7bbfb1a9 100644 --- a/notifications_utils/recipients.py +++ b/notifications_utils/recipients.py @@ -83,8 +83,10 @@ class RecipientCSV: def guestlist(self, value): try: self._guestlist = list(value) - except TypeError as te: - current_app.logger.exception(f"Type error setting the guest list to {value}") + except TypeError: + current_app.logger.exception( + f"Type error setting the guest list to {value}" + ) self._guestlist = [] @property @@ -112,7 +114,9 @@ class RecipientCSV: try: self._placeholders = list(value) + self.recipient_column_headers except TypeError: - current_app.logger.exception(f"TypeError setting the placeholders to {value}") + current_app.logger.exception( + f"TypeError setting the placeholders to {value}" + ) self._placeholders = self.recipient_column_headers self.placeholders_as_column_keys = [ InsensitiveDict.make_key(placeholder) for placeholder in self._placeholders @@ -514,7 +518,9 @@ def is_us_phone_number(number): try: return _get_country_code(number) == us_prefix except NumberParseException: - current_app.logger.exception("NumberParseException checking if phone number is US number") + current_app.logger.exception( + "NumberParseException checking if phone number is US number" + ) return False @@ -660,7 +666,9 @@ def try_validate_and_format_phone_number(number, international=None, log_msg=Non try: return validate_and_format_phone_number(number, international) except InvalidPhoneError as exc: - current_app.logger.exception("InvalidPhoneNumber while trying to validate and format phone number") + current_app.logger.exception( + "InvalidPhoneNumber while trying to validate and format phone number" + ) if log_msg: current_app.logger.warning("{}: {}".format(log_msg, exc)) return number @@ -738,7 +746,9 @@ def format_phone_number_human_readable(phone_number): phone_number = validate_phone_number(phone_number, international=True) except InvalidPhoneError: # if there was a validation error, we want to shortcut out here, but still display the number on the front end - current_app.logger.exception("InvalidPhoneError trying to format_phone_number_human_readable()") + current_app.logger.exception( + "InvalidPhoneError trying to format_phone_number_human_readable()" + ) return phone_number international_phone_info = get_international_phone_info(phone_number)