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

Logging approach creates redundant events on each exception #258

Closed
Kaveshnikov opened this issue Jul 14, 2022 · 2 comments · Fixed by #296
Closed

Logging approach creates redundant events on each exception #258

Kaveshnikov opened this issue Jul 14, 2022 · 2 comments · Fixed by #296
Assignees

Comments

@Kaveshnikov
Copy link

Kaveshnikov commented Jul 14, 2022

Hello. I use this library in one of my projects. I have noticed that across the library codebase on each exception 2 logging records are created. This approach complicates integrations with errors monitoring solutions, for example Sentry. An event will be created on each logging record. For example, a record with message "unexpected error" (created here) doesn't provide any valuable information for the investigation. Also, logging.Logger.exception() method is not supposed to be used like that. It will get the Exception object implicitly and log the traceback by default. So, we only need to provide some meaningful message as an argument for this method.

I suggest to refactor all places with such an approach to create only one logging record. For example, in this place it will be like this:

current_app.logger.exception('unexpected error')
@nycholas nycholas self-assigned this Jul 15, 2022
@nycholas
Copy link
Member

Hi @Kaveshnikov,

I suggest to refactor all places with such an approach to create only one logging record. For example, in this place it will be like this:
current_app.logger.exception('unexpected error')

The excellent suggestion, I will accept that.
A new medium release will be launched.

Thank you.

@nycholas
Copy link
Member

Some examples to further information:

>>> try:
...     1/0
... except ZeroDivisionError as e:
...     logging.exception('xxx')
...
...
ERROR:root:xxx
Traceback (most recent call last):
  File "<bpython-input-9>", line 2, in <module>
    1/0
ZeroDivisionError: division by zero
>>> try:
...     1/0
... except ZeroDivisionError as e:
...     logging.error('xxx')
...
...
ERROR:root:xxx
>>> try:
...     1/0
... except ZeroDivisionError:
...     logging.exception('xxx')
...
...
ERROR:root:xxx
Traceback (most recent call last):
  File "<bpython-input-23>", line 2, in <module>
    1/0
ZeroDivisionError: division by zero
>>> try:
...     1/0
... except:
...     import logging
...     logging.exception('xxx')
...
...
ERROR:root:xxx
Traceback (most recent call last):
  File "<bpython-input-30>", line 2, in <module>
    1/0
ZeroDivisionError: division by zero

nycholas added a commit that referenced this issue Sep 14, 2022
nycholas added a commit that referenced this issue Oct 19, 2022
* Prepare code to create a typeshed stubs
* Add Pytype to analysis type code
* Add examples using Cerberus as validator (#37)
* Load fonts locally [offline mode] (#55)
* Remove redudant events logs (#258)
* Bump version in pre-commit-config.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants