Skip to content

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ddtrace/internal/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ def get_logger(name: str) -> logging.Logger:
logger = logging.getLogger(name)
# addFilter will only add the filter if it is not already present
logger.addFilter(log_filter)

# Set the log level from the environment variable of the closest parent
# logger.
if name.startswith("ddtrace."): # for the whole of ddtrace we have DD_TRACE_DEBUG
(hierarchy := name.split(".")).pop(0) # remove "ddtrace"
while hierarchy:
if (level_name := os.getenv("_DD_" + "_".join(hierarchy).upper() + "_LOG_LEVEL", None)) is not None:
if (level := getattr(logging, level_name, None)) is not None:
logger.setLevel(level)
break
hierarchy.pop()

return logger


Expand Down
Loading