-
Notifications
You must be signed in to change notification settings - Fork 440
chore: configurable logger levels #13562
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -335,3 +335,29 @@ def test_logger_does_not_add_handler_when_configured(): | |
ddtrace_logger = logging.getLogger("ddtrace") | ||
assert len(ddtrace_logger.handlers) == 0 | ||
assert ddtrace_logger.handlers == [] | ||
|
||
|
||
def test_logger_log_level_from_env(monkeypatch): | ||
monkeypatch.setenv("_DD_TESTING_DEBUG_LOG_LEVEL", "DEBUG") | ||
monkeypatch.setenv("_DD_TESTING_WARNING_LOG_LEVEL", "WARNING") | ||
monkeypatch.setenv("_DD_PACKAGE_WITH_UNDERSCORE_SUBMODULE_LOG_LEVEL", "ERROR") | ||
|
||
import ddtrace.internal.logger as dd_logger | ||
|
||
original_trie = dd_logger.LOG_LEVEL_TRIE | ||
dd_logger.LOG_LEVEL_TRIE = dd_logger.LoggerPrefix.build_trie() | ||
print(dd_logger.LOG_LEVEL_TRIE) | ||
|
||
try: | ||
assert get_logger("ddtrace.testing.debug.foo.bar").level == logging.DEBUG | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we shouldn't have to manually set the level for all children.... right? meaning You should evaluate via >>> a = logging.getLogger("a")
>>> b = logging.getLogger("a.b")
>>> a.setLevel(logging.DEBUG)
>>> b.isEnabledFor(logging.DEBUG)
True
>>> a.setLevel(logging.ERROR)
>>> b.isEnabledFor(logging.DEBUG)
False There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah that's a good point, but what if the logger for |
||
assert get_logger("ddtrace.testing.debug.foo").level == logging.DEBUG | ||
assert get_logger("ddtrace.testing.debug").level == logging.DEBUG | ||
assert get_logger("ddtrace.testing").level < logging.DEBUG | ||
|
||
assert get_logger("ddtrace.testing.warning.foo.bar").level == logging.WARNING | ||
assert get_logger("ddtrace.testing.warning.foo").level == logging.WARNING | ||
assert get_logger("ddtrace.testing.warning").level == logging.WARNING | ||
|
||
assert get_logger("ddtrace.package_with_underscore.submodule").level == logging.ERROR | ||
finally: | ||
dd_logger.LOG_LEVEL_TRIE = original_trie |
Uh oh!
There was an error while loading. Please reload this page.