Skip to content

Commit

Permalink
Remove excessive logging on exception
Browse files Browse the repository at this point in the history
log.exception already contains exception info, there is no need
to log twice with separate logging levels.

Signed-off-by: Kaifeng Wang <[email protected]>
  • Loading branch information
kaifeng authored and ansasaki committed Feb 19, 2025
1 parent e271264 commit 4717d96
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 18 deletions.
3 changes: 1 addition & 2 deletions demo/agent_monitor/tenant_agent_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ def initthread():
logger.warning("POST returning 400 response. uri not supported")
except Exception as err:
keylime.web_util.echo_json_response(self, 400, "Exception error: %s" % err)
logger.warning("POST returning 400 response. Exception error: %s" % err)
logger.exception(err)
logger.exception("POST returning 400 response.")

def put(self):
"""This method handles the PUT requests to add agents to the Agent Monitor.
Expand Down
9 changes: 3 additions & 6 deletions keylime/cloud_verifier_tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,7 @@ def post(self) -> None:
logger.warning("POST returning 400 response. uri not supported")
except Exception as e:
web_util.echo_json_response(self, 400, f"Exception error: {str(e)}")
logger.warning("POST returning 400 response. Exception error: %s", e)
logger.exception(e)
logger.exception("POST returning 400 response.")

def put(self) -> None:
"""This method handles the PUT requests to add agents to the Cloud Verifier.
Expand Down Expand Up @@ -845,8 +844,7 @@ def put(self) -> None:

except Exception as e:
web_util.echo_json_response(self, 400, f"Exception error: {str(e)}")
logger.warning("PUT returning 400 response. Exception error: %s", e)
logger.exception(e)
logger.exception("PUT returning 400 response.")

def data_received(self, chunk: Any) -> None:
raise NotImplementedError()
Expand Down Expand Up @@ -1944,8 +1942,7 @@ async def process_agent(
raise Exception("nothing should ever fall out of this!")

except Exception as e:
logger.error("Polling thread error for agent ID %s: %s", agent["agent_id"], e)
logger.exception(e)
logger.exception("Polling thread error for agent ID %s", agent["agent_id"])
failure.add_event(
"exception", {"context": "Agent caused the verifier to throw an exception", "data": str(e)}, False
)
Expand Down
2 changes: 1 addition & 1 deletion keylime/db/keylime_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# make sure referential integrity is working for SQLite
@event.listens_for(Engine, "connect") # type: ignore
def _set_sqlite_pragma(dbapi_connection: SQLite3Connection, _) -> None:
def _set_sqlite_pragma(dbapi_connection: SQLite3Connection, _: Any) -> None:
if isinstance(dbapi_connection, SQLite3Connection):
cursor = dbapi_connection.cursor()
cursor.execute("PRAGMA foreign_keys=ON")
Expand Down
2 changes: 1 addition & 1 deletion keylime/models/base/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# make sure referential integrity is working for SQLite
@event.listens_for(Engine, "connect") # type: ignore
def _set_sqlite_pragma(dbapi_connection: SQLite3Connection, _) -> None:
def _set_sqlite_pragma(dbapi_connection: SQLite3Connection, _: Any) -> None:
if isinstance(dbapi_connection, SQLite3Connection):
cursor = dbapi_connection.cursor()
cursor.execute("PRAGMA foreign_keys=ON")
Expand Down
13 changes: 5 additions & 8 deletions keylime/tpm/tpm_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ def encrypt_aik_with_ek(uuid: str, ek_tpm: bytes, aik_tpm: bytes) -> Optional[Tu
credentialblob = tpm_util.makecredential(ek_tpm, challenge, bytes.fromhex(aik_name))
keyblob = base64.b64encode(credentialblob)

except Exception as e:
logger.error("Error encrypting AIK with EK: %s", str(e))
logger.exception(e)
except Exception:
logger.exception("Error encrypting AIK with EK")
raise

return (keyblob, key)
Expand Down Expand Up @@ -145,9 +144,8 @@ def _tpm2_clock_info_from_quote(quote: str, compressed: bool) -> Dict[str, Any]:

try:
return tpm2_objects.get_tpms_attest_clock_info(quoteblob)
except Exception as e:
logger.error("Error extracting clock info from quote: %s", str(e))
logger.exception(e)
except Exception:
logger.exception("Error extracting clock info from quote")
return {}

@staticmethod
Expand Down Expand Up @@ -175,8 +173,7 @@ def _tpm2_checkquote(
try:
pcrs_dict = tpm_util.checkquote(aikFromRegistrar, nonce, sigblob, quoteblob, pcrblob, hash_alg)
except Exception as e:
logger.error("Error verifying quote: %s", str(e))
logger.exception(e)
logger.exception("Error verifying quote")
return {}, str(e)

return pcrs_dict, ""
Expand Down

0 comments on commit 4717d96

Please sign in to comment.