-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix logging configuration to prevent OpenTelemetry handler conflicts #8269
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 | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -55,29 +55,20 @@ def enable_logging(): | |||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
def configure_dspy_loggers(root_module_name): | ||||||||||||||||||||||||||||||||||
logging.config.dictConfig( | ||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||
"version": 1, | ||||||||||||||||||||||||||||||||||
"disable_existing_loggers": False, | ||||||||||||||||||||||||||||||||||
"formatters": { | ||||||||||||||||||||||||||||||||||
"dspy_formatter": { | ||||||||||||||||||||||||||||||||||
"format": LOGGING_LINE_FORMAT, | ||||||||||||||||||||||||||||||||||
"datefmt": LOGGING_DATETIME_FORMAT, | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
"handlers": { | ||||||||||||||||||||||||||||||||||
"dspy_handler": { | ||||||||||||||||||||||||||||||||||
"formatter": "dspy_formatter", | ||||||||||||||||||||||||||||||||||
"class": "logging.StreamHandler", | ||||||||||||||||||||||||||||||||||
"stream": DSPY_LOGGING_STREAM, | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
"loggers": { | ||||||||||||||||||||||||||||||||||
root_module_name: { | ||||||||||||||||||||||||||||||||||
"handlers": ["dspy_handler"], | ||||||||||||||||||||||||||||||||||
"level": "INFO", | ||||||||||||||||||||||||||||||||||
"propagate": False, | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||
formatter = logging.Formatter(fmt=LOGGING_LINE_FORMAT, datefmt=LOGGING_DATETIME_FORMAT) | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
handler = logging.StreamHandler(stream=DSPY_LOGGING_STREAM) | ||||||||||||||||||||||||||||||||||
handler.setFormatter(formatter) | ||||||||||||||||||||||||||||||||||
handler.set_name("dspy_handler") | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
logger = logging.getLogger(root_module_name) | ||||||||||||||||||||||||||||||||||
logger.setLevel(logging.INFO) | ||||||||||||||||||||||||||||||||||
logger.propagate = False | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
for existing_handler in logger.handlers[:]: | ||||||||||||||||||||||||||||||||||
if getattr(existing_handler, "name", None) == "dspy_handler": | ||||||||||||||||||||||||||||||||||
Comment on lines
+62
to
+69
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. [nitpick] The handler name string "dspy_handler" is duplicated in multiple places; consider defining it as a constant to avoid typos and simplify updates.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback 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. I kept it how it was before. if needed I can just create a constant |
||||||||||||||||||||||||||||||||||
logger.removeHandler(existing_handler) | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
logger.addHandler(handler) | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
return logger |
Uh oh!
There was an error while loading. Please reload this page.