Skip to content
34 changes: 29 additions & 5 deletions backend/app/logging/setup_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,38 @@ def emit(self, record: logging.LogRecord) -> None:
if "." in module_name:
module_name = module_name.split(".")[-1]

# Create a message that includes the original module in the format
# Create a new log record with modified message to prevent recursion
# We modify the record in place and pass it directly to handlers
msg = record.getMessage()

# Find the appropriate logger
logger = get_logger(module_name)
# Create a new record to avoid modifying the original
new_record = logging.LogRecord(
name=module_name,
level=record.levelno,
pathname=record.pathname,
lineno=record.lineno,
msg=f"[{module_name}] {msg}",
args=(),
exc_info=None,
func=record.funcName,
sinfo=None,
)

# Log the message with our custom formatting
logger.log(record.levelno, f"[uvicorn] {msg}")
# Copy extra attributes
new_record.created = record.created
new_record.msecs = record.msecs
new_record.relativeCreated = record.relativeCreated

# Get root logger's handlers and call them directly to avoid recursion
root_logger = logging.getLogger()
for handler in root_logger.handlers:
# Skip this InterceptHandler to prevent recursion
if handler is not self and not isinstance(handler, InterceptHandler):
try:
handler.handle(new_record)
except Exception:
# Silently ignore handler errors to prevent crashes
pass


def configure_uvicorn_logging(component_name: str) -> None:
Expand Down
10 changes: 7 additions & 3 deletions docs/backend/backend_python/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1117,9 +1117,14 @@
"in": "query",
"required": false,
"schema": {
"$ref": "#/components/schemas/InputType",
"allOf": [
{
"$ref": "#/components/schemas/InputType"
}
],
"description": "Choose input type: 'path' or 'base64'",
"default": "path"
"default": "path",
"title": "Input Type"
},
"description": "Choose input type: 'path' or 'base64'"
}
Expand Down Expand Up @@ -2199,7 +2204,6 @@
"metadata": {
"anyOf": [
{
"additionalProperties": true,
"type": "object"
},
{
Expand Down
31 changes: 25 additions & 6 deletions sync-microservice/app/logging/setup_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,33 @@ def emit(self, record: logging.LogRecord) -> None:
if "." in module_name:
module_name = module_name.split(".")[-1]

# Create a message that includes the original module in the format
# Build a new record so we do not re-enter the logging pipeline
msg = record.getMessage()
new_record = logging.LogRecord(
name=module_name,
level=record.levelno,
pathname=record.pathname,
lineno=record.lineno,
msg=f"[uvicorn] {msg}",
args=(),
exc_info=record.exc_info,
func=record.funcName,
sinfo=record.stack_info,
)

# Find the appropriate logger
logger = get_logger(module_name)

# Log the message with our custom formatting
logger.log(record.levelno, f"[uvicorn] {msg}")
# Preserve timing metadata
new_record.created = record.created
new_record.msecs = record.msecs
new_record.relativeCreated = record.relativeCreated

# Send directly to root handlers, skipping intercepts to avoid recursion
root_logger = logging.getLogger()
for handler in root_logger.handlers:
if handler is not self and not isinstance(handler, InterceptHandler):
try:
handler.handle(new_record)
except Exception:
pass


def configure_uvicorn_logging(component_name: str) -> None:
Expand Down