Log And Rethrow Duplication (ARCH2166)
هذا المحتوى غير متوفر بلغتك بعد.
Key python.logging.log-and-rethrow · Severity warning · Category logging
Logging an exception and then rethrowing it in the same handler produces duplicate log entries, since it gets logged again higher in the stack. This causes the same error to appear as multiple entries.
Incorrect
Section titled “Incorrect”def handle(req): try: return process(req) except ValidationError: logger.exception("Validation error") raiseCorrect
Section titled “Correct”def handle(req): try: return process(req) except ValidationError: raiseJust re-raise the exception; log it at a single layer that owns the responsibility.