Skip to content

Commit 3e1185f

Browse files
Fix logging configuration to prevent OpenTelemetry handler conflicts (#8269)
* fix/logger-config-issue Signed-off-by: dmavrommatis <[email protected]> * remove the return value * make constant --------- Signed-off-by: dmavrommatis <[email protected]> Co-authored-by: chenmoneygithub <[email protected]>
1 parent 5bc4a15 commit 3e1185f

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

dspy/utils/logging_utils.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,19 @@ def enable_logging():
5555

5656

5757
def configure_dspy_loggers(root_module_name):
58-
logging.config.dictConfig(
59-
{
60-
"version": 1,
61-
"disable_existing_loggers": False,
62-
"formatters": {
63-
"dspy_formatter": {
64-
"format": LOGGING_LINE_FORMAT,
65-
"datefmt": LOGGING_DATETIME_FORMAT,
66-
},
67-
},
68-
"handlers": {
69-
"dspy_handler": {
70-
"formatter": "dspy_formatter",
71-
"class": "logging.StreamHandler",
72-
"stream": DSPY_LOGGING_STREAM,
73-
},
74-
},
75-
"loggers": {
76-
root_module_name: {
77-
"handlers": ["dspy_handler"],
78-
"level": "INFO",
79-
"propagate": False,
80-
},
81-
},
82-
}
83-
)
58+
formatter = logging.Formatter(fmt=LOGGING_LINE_FORMAT, datefmt=LOGGING_DATETIME_FORMAT)
59+
60+
dspy_handler_name = "dspy_handler"
61+
handler = logging.StreamHandler(stream=DSPY_LOGGING_STREAM)
62+
handler.setFormatter(formatter)
63+
handler.set_name(dspy_handler_name)
64+
65+
logger = logging.getLogger(root_module_name)
66+
logger.setLevel(logging.INFO)
67+
logger.propagate = False
68+
69+
for existing_handler in logger.handlers[:]:
70+
if getattr(existing_handler, "name", None) == dspy_handler_name:
71+
logger.removeHandler(existing_handler)
72+
73+
logger.addHandler(handler)

0 commit comments

Comments
 (0)