Skip to content

Commit

Permalink
perf: πŸ§‘β€πŸ’» Move some warning log statements behind debug toggle.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrew82 committed Oct 30, 2024
1 parent 12b0947 commit 09cdefc
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ def load_devices(self):
dev_role = "Unknown"
vendor = "Cisco"
if not dev.get("hostname"):
self.job.logger.warning(f"Device {dev['id']} is missing hostname so will be skipped.")
if self.job.debug:
self.job.logger.warning(f"Device {dev['id']} is missing hostname so will be skipped.")
dev["field_validation"] = {
"reason": "Failed due to missing hostname.",
}
Expand Down Expand Up @@ -340,7 +341,8 @@ def load_devices(self):
or loc_data.get("building") == "Unassigned"
or not loc_data.get("building")
):
self.job.logger.warning(f"Device {dev['hostname']} is missing building so will not be imported.")
if self.job.debug:
self.job.logger.warning(f"Device {dev['hostname']} is missing building so will not be imported.")
dev["field_validation"] = {
"reason": "Missing building assignment.",
"device_details": dev_details,
Expand All @@ -355,9 +357,10 @@ def load_devices(self):
)
device_found = self.get(self.device, dev["hostname"])
if device_found:
self.job.logger.warning(
f"Duplicate device attempting to be loaded for {dev['hostname']} with ID: {dev['id']} so will not be imported."
)
if self.job.debug:
self.job.logger.warning(
f"Duplicate device attempting to be loaded for {dev['hostname']} with ID: {dev['id']} so will not be imported."
)
dev["field_validation"] = {
"reason": "Failed due to duplicate device found.",
"device_details": dev_details,
Expand Down Expand Up @@ -385,7 +388,8 @@ def load_devices(self):
self.add(new_dev)
self.load_ports(device_id=dev["id"], dev=new_dev, mgmt_addr=dev["managementIpAddress"])
except ValidationError as err:
self.job.logger.warning(f"Unable to load device {dev['hostname']}. {err}")
if self.job.debug:
self.job.logger.warning(f"Unable to load device {dev['hostname']}. {err}")
dev["field_validation"] = {
"reason": f"Failed validation. {err}",
"device_details": dev_details,
Expand All @@ -412,7 +416,7 @@ def load_ports(self, device_id: str, dev: DnaCenterDevice, mgmt_addr: str = ""):
"mac_addr": port["macAddress"].upper() if port.get("macAddress") else None,
},
)
if found_port:
if found_port and self.job.debug:
self.job.logger.warning(
f"Duplicate port attempting to be loaded, {port['portName']} for {dev.name}"
)
Expand Down Expand Up @@ -486,7 +490,7 @@ def load_ip_address(self, host: str, mask_length: int, prefix: str):
self.add(new_prefix)
try:
ip_found = self.get(self.ipaddress, {"host": host, "namespace": namespace})
if ip_found:
if ip_found and self.job.debug:
self.job.logger.warning(f"Duplicate IP Address attempting to be loaded: {host} in {prefix}")
except ObjectNotFound:
if self.job.debug:
Expand Down

0 comments on commit 09cdefc

Please sign in to comment.