Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception logging #248

Closed
lchen-2101 opened this issue May 21, 2024 · 0 comments · Fixed by #253
Closed

Fix exception logging #248

lchen-2101 opened this issue May 21, 2024 · 0 comments · Fixed by #253
Assignees
Labels
bug Something isn't working

Comments

@lchen-2101
Copy link
Collaborator

We're logging exceptions incorrectly in some areas of the code.
e.g.

try:
    ...
except Exception as e:
    log.error("some custom message", e)

This would cause the error not all arguments converted during string formatting, which is because in the example, subsequent unnamed arguments are expected to be part of interpolated string for the custom message.
e.g.

log.error("some custom message with variable: %s", some_variable)

We can log just the exception without custom message:

try:
    ...
except Exception as e:
    log.error(e)

however to log the exception with additional custom message, we should be doing:

try:
    ...
except Exception as e:
    log.exception("some custom message")

log.exception("some message") is the equivalent to log.error("some message", exc_info=True), which having exc_info set to true causes the exception information to be added to the log message. Additionally, we can add stack_info=True to the logging parameters to show the unwound stack leading up to the logging call (not the same as exception stack trace).

@lchen-2101 lchen-2101 added the bug Something isn't working label May 21, 2024
@lchen-2101 lchen-2101 self-assigned this May 21, 2024
jcadam14 added a commit that referenced this issue May 28, 2024
closes #248

---------

Co-authored-by: jcadam14 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant