mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-30 19:08:33 -04:00
improve logging
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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("/<uuid:user_id>/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)
|
||||
|
||||
Reference in New Issue
Block a user