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

Make logging level of the django app configurable #2078

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

yarikoptic
Copy link
Member

ATM we do not have a single DEBUG level log statement, but I hope that logging would be enriched. Adding such control would also allow to make log less talkative if so desired by setting it to WARNING level. But also would simplify addition and use of new log statements. E.g. I would right away add it into dandi-cli docker-compose setup so to help in the future troubleshooting issues like

ATM we do not have a single DEBUG level log statement, but I hope
that logging would be enriched. Adding such control would also allow
to make log less talkative if so desired by setting it to WARNING level.
But also would simplify addition and use of new log statements
@yarikoptic yarikoptic added DX Affects developer experience internal Changes only affect the internal API labels Nov 20, 2024
@yarikoptic yarikoptic requested a review from waxlamp December 3, 2024 16:57
These are not needed here, as they are already part of the setting
definition (that is, `settings.DANDI_LOG_LEVEL` always exists and has
the correct default value if it is not set explicitly).
The [`logging` module
docs](https://docs.python.org/3/library/logging.html#logging.Logger.setLevel)
explain that `setLevel()` can handle the string representations of the
logging levels. This allows the setting value to be directly tied to
what is passed in, and `setLevel()` also does a "validation" on the
value and will refuse to process levels that don't exist.
Copy link
Member

@waxlamp waxlamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a few commits to simplify the code. If you're ok with those, let me know and I will merge.

@@ -50,13 +50,15 @@ def ready(self):
import dandiapi.api.checks # noqa: F401, RUF100
import dandiapi.api.signals # noqa: F401

logging.getLogger(__name__).setLevel(settings.DANDI_LOG_LEVEL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was originally logging.getLogger(__name__.split('.')[0]), but looking through the codebase and at the logging docs, it seems logging.getLogger(__name__) is a standard practice. Was there a reason you had it the other way? (If necessary, we can revert 6addfac, which makes the change.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this does not have the desired effect (of changing the logging level for all loggers). Instead, we need to omit the __name__ argument so as to affect the root logger. See b07bfe1.

This needs to be `logging.INFO` so that Sentry can propery construct
breadcrumbs within its error reports.
Copy link
Member

@waxlamp waxlamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple more changes to eliminate some bugs.

dandiapi/api/apps.py Outdated Show resolved Hide resolved
@@ -50,13 +50,15 @@ def ready(self):
import dandiapi.api.checks # noqa: F401, RUF100
import dandiapi.api.signals # noqa: F401

logging.getLogger(__name__).setLevel(settings.DANDI_LOG_LEVEL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this does not have the desired effect (of changing the logging level for all loggers). Instead, we need to omit the __name__ argument so as to affect the root logger. See b07bfe1.

@@ -50,6 +50,8 @@ def ready(self):
import dandiapi.api.checks # noqa: F401, RUF100
import dandiapi.api.signals # noqa: F401

logging.getLogger().setLevel(settings.DANDI_LOG_LEVEL)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @waxlamp for catching the initial limitation! but I do not think we should go this wild, what about affecting only dandi ? i.e. smth like

Suggested change
logging.getLogger().setLevel(settings.DANDI_LOG_LEVEL)
logging.getLogger(__name__.split('.', 1)[0]).setLevel(settings.DANDI_LOG_LEVEL)

? otherwise, if to debug our code we turn to DEBUG level globally -- could lead to excessive amount of noise from all kinds of libraries we use. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see what you were going for now. I've added this back (along with explanatory comment) in dc3549d.

@yarikoptic yarikoptic requested a review from waxlamp December 17, 2024 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Affects developer experience internal Changes only affect the internal API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants