Fix logging

This commit is contained in:
zandercymatics 2023-11-07 18:21:48 -07:00
parent 4a7aa0b484
commit 87254543f4
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 41 additions and 29 deletions

View file

@ -71,7 +71,7 @@ class FileTransitionLog:
def create_log_item( def create_log_item(
self, file_type, code, message, domain_name=None, add_to_list=True self, file_type, code, message, domain_name=None, add_to_list=True, minimal_logging=True
): ):
"""Creates and returns an LogItem object. """Creates and returns an LogItem object.
@ -84,6 +84,15 @@ class FileTransitionLog:
dict_name = (file_type, domain_name) dict_name = (file_type, domain_name)
self._add_to_log_list(dict_name, log) self._add_to_log_list(dict_name, log)
restrict_type = []
if minimal_logging:
restrict_type = [LogCode.INFO, LogCode.WARNING]
TerminalHelper.print_conditional(
log.code not in restrict_type,
log.message,
log.code,
)
return log return log
def _add_to_log_list(self, log_name, log): def _add_to_log_list(self, log_name, log):
@ -179,9 +188,7 @@ class LoadExtraTransitionDomain:
updated_transition_domain.save() updated_transition_domain.save()
updated_transition_domains.append(updated_transition_domain) updated_transition_domains.append(updated_transition_domain)
if self.debug:
# Display errors for this specific domain
self.parse_logs.display_logs_by_domain_name(domain_name)
logger.info( logger.info(
f"{TerminalColors.OKCYAN}" f"{TerminalColors.OKCYAN}"
f"Successfully updated {domain_name}" f"Successfully updated {domain_name}"
@ -242,6 +249,7 @@ class LoadExtraTransitionDomain:
"Could not add epp_creation_date and epp_expiration_date " "Could not add epp_creation_date and epp_expiration_date "
f"on {domain_name}, no data exists.", f"on {domain_name}, no data exists.",
domain_name, domain_name,
not self.debug
) )
return transition_domain return transition_domain
@ -287,6 +295,7 @@ class LoadExtraTransitionDomain:
LogCode.ERROR, LogCode.ERROR,
f"Could not add federal_agency on {domain_name}, no data exists.", f"Could not add federal_agency on {domain_name}, no data exists.",
domain_name, domain_name,
not self.debug
) )
return transition_domain return transition_domain
@ -301,6 +310,7 @@ class LoadExtraTransitionDomain:
LogCode.ERROR, LogCode.ERROR,
f"Could not add inactive agency {info.agencyname} on {domain_name}", f"Could not add inactive agency {info.agencyname} on {domain_name}",
domain_name, domain_name,
not self.debug
) )
return transition_domain return transition_domain
@ -310,6 +320,7 @@ class LoadExtraTransitionDomain:
LogCode.ERROR, LogCode.ERROR,
f"Could not add non-federal agency {info.agencyname} on {domain_name}", f"Could not add non-federal agency {info.agencyname} on {domain_name}",
domain_name, domain_name,
not self.debug
) )
return transition_domain return transition_domain
@ -342,6 +353,7 @@ class LoadExtraTransitionDomain:
LogCode.ERROR, LogCode.ERROR,
f"Could not add domain_type on {domain_name}, no data exists.", f"Could not add domain_type on {domain_name}, no data exists.",
domain_name, domain_name,
not self.debug
) )
return transition_domain return transition_domain
@ -364,6 +376,7 @@ class LoadExtraTransitionDomain:
LogCode.ERROR, LogCode.ERROR,
f"Could not add inactive domain_type {domain_type[0]} on {domain_name}", f"Could not add inactive domain_type {domain_type[0]} on {domain_name}",
domain_name, domain_name,
not self.debug
) )
return transition_domain return transition_domain
@ -424,6 +437,7 @@ class LoadExtraTransitionDomain:
LogCode.ERROR, LogCode.ERROR,
f"Could not add organization_name on {domain_name}, no data exists.", f"Could not add organization_name on {domain_name}, no data exists.",
domain_name, domain_name,
not self.debug
) )
return transition_domain return transition_domain
@ -457,6 +471,7 @@ class LoadExtraTransitionDomain:
LogCode.INFO, LogCode.INFO,
f"Added {var_name} as '{changed_value}' on {domain_name}", f"Added {var_name} as '{changed_value}' on {domain_name}",
domain_name, domain_name,
not self.debug
) )
else: else:
self.parse_logs.create_log_item( self.parse_logs.create_log_item(
@ -464,6 +479,7 @@ class LoadExtraTransitionDomain:
LogCode.WARNING, LogCode.WARNING,
f"Updated existing {var_name} to '{changed_value}' on {domain_name}", f"Updated existing {var_name} to '{changed_value}' on {domain_name}",
domain_name, domain_name,
not self.debug
) )
# Property getters, i.e. orgid or domaintypeid # Property getters, i.e. orgid or domaintypeid
@ -583,7 +599,7 @@ class LoadExtraTransitionDomain:
desired_type = self.parsed_data_container.file_data.get(file_type) desired_type = self.parsed_data_container.file_data.get(file_type)
if desired_type is None: if desired_type is None:
self.parse_logs.create_log_item( self.parse_logs.create_log_item(
file_type, LogCode.ERROR, f"Type {file_type} does not exist" file_type, LogCode.ERROR, f"Type {file_type} does not exist",
) )
return None return None

View file

@ -394,6 +394,25 @@ class TestMigrations(TestCase):
expected_missing_domain_invitations, expected_missing_domain_invitations,
) )
expected_anomaly_domains = Domain.objects.filter(name="anomaly.gov")
self.assertEqual(expected_anomaly_domains.count(), 1)
expected_anomaly = expected_anomaly_domains.get()
self.assertEqual(expected_anomaly.expiration_date, "test")
self.assertEqual(expected_anomaly.creation_date, "test")
self.assertEqual(expected_anomaly.name, "anomaly.gov")
self.assertEqual(expected_anomaly.state, "ready")
expected_testdomain_domains = Domain.objects.filter(name="anomaly.gov")
self.assertEqual(expected_testdomain_domains.count(), 1)
expected_testdomain = expected_testdomain_domains.get()
self.assertEqual(expected_testdomain.expiration_date, "test")
self.assertEqual(expected_testdomain.creation_date, "test")
self.assertEqual(expected_testdomain.name, "anomaly.gov")
self.assertEqual(expected_testdomain.state, "ready")
expected_domains = [ expected_domains = [
Domain( Domain(
expiration_date=None, expiration_date=None,
@ -405,32 +424,9 @@ class TestMigrations(TestCase):
name="testdomain.gov", name="testdomain.gov",
state="ready", state="ready",
), ),
Domain(
expiration_date=None,
name="fakewebsite1.gov",
state="on hold",
),
Domain(
expiration_date=None,
name="fakewebsite2.gov",
state="on hold",
),
Domain(
expiration_date=None,
name="fakewebsite3.gov",
state="ready",
),
] ]
for domain in Domain.objects.all(): for domain in Domain.objects.all():
print(f"""
Domain(
expiration_date={domain.expiration_date},
name="{domain.name}",
state="{domain.state}",
),
"""
)
for expected in expected_domains: for expected in expected_domains:
expected.id = domain.id expected.id = domain.id
expected.created_at = domain.created_at expected.created_at = domain.created_at