Skip to content

Commit a3c0c6b

Browse files
committed
Fix merge conflict in both logging handlers
1 parent 99fdcb4 commit a3c0c6b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

sync-microservice/app/logging/setup_logging.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,32 +248,37 @@ def emit(self, record: logging.LogRecord) -> None:
248248
if "." in module_name:
249249
module_name = module_name.split(".")[-1]
250250

251-
# Build a new record so we do not re-enter the logging pipeline
251+
# Create a new log record with modified message to prevent recursion
252+
# We modify the record in place and pass it directly to handlers
252253
msg = record.getMessage()
254+
255+
# Create a new record to avoid modifying the original
253256
new_record = logging.LogRecord(
254257
name=module_name,
255258
level=record.levelno,
256259
pathname=record.pathname,
257260
lineno=record.lineno,
258-
msg=f"[uvicorn] {msg}",
261+
msg=f"[{module_name}] {msg}",
259262
args=(),
260263
exc_info=None,
261264
func=record.funcName,
262265
sinfo=None,
263266
)
264267

265-
# Preserve timing metadata
268+
# Copy extra attributes
266269
new_record.created = record.created
267270
new_record.msecs = record.msecs
268271
new_record.relativeCreated = record.relativeCreated
269272

270-
# Send directly to root handlers, skipping intercepts to avoid recursion
273+
# Get root logger's handlers and call them directly to avoid recursion
271274
root_logger = logging.getLogger()
272275
for handler in root_logger.handlers:
276+
# Skip this InterceptHandler to prevent recursion
273277
if handler is not self and not isinstance(handler, InterceptHandler):
274278
try:
275279
handler.handle(new_record)
276280
except Exception:
281+
# Silently ignore handler errors to prevent crashes
277282
pass
278283

279284

0 commit comments

Comments
 (0)