Skip to content

Commit 4647bac

Browse files
authored
Fix infinite recursion in InterceptHandler logging (#940)
1 parent 4bdf1d3 commit 4647bac

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

backend/app/logging/setup_logging.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,16 @@ def emit(self, record: logging.LogRecord) -> None:
243243
# Create a message that includes the original module in the format
244244
msg = record.getMessage()
245245

246-
# Find the appropriate logger
247-
logger = get_logger(module_name)
248-
249-
# Log the message with our custom formatting
250-
logger.log(record.levelno, f"[uvicorn] {msg}")
246+
record.msg = f"[{module_name}] {msg}"
247+
record.args = ()
248+
# Clear exception / stack info to avoid duplicate traces
249+
record.exc_info = None
250+
record.stack_info = None
251+
252+
root_logger = logging.getLogger()
253+
for handler in root_logger.handlers:
254+
if handler is not self:
255+
handler.handle(record)
251256

252257

253258
def configure_uvicorn_logging(component_name: str) -> None:

sync-microservice/app/logging/setup_logging.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,16 @@ def emit(self, record: logging.LogRecord) -> None:
251251
# Create a message that includes the original module in the format
252252
msg = record.getMessage()
253253

254-
# Find the appropriate logger
255-
logger = get_logger(module_name)
256-
257-
# Log the message with our custom formatting
258-
logger.log(record.levelno, f"[uvicorn] {msg}")
254+
record.msg = f"[{module_name}] {msg}"
255+
record.args = ()
256+
# Clear exception / stack info to avoid duplicate traces
257+
record.exc_info = None
258+
record.stack_info = None
259+
260+
root_logger = logging.getLogger()
261+
for handler in root_logger.handlers:
262+
if handler is not self:
263+
handler.handle(record)
259264

260265

261266
def configure_uvicorn_logging(component_name: str) -> None:

0 commit comments

Comments
 (0)