Skip to content

Latest commit

 

History

History
29 lines (23 loc) · 689 Bytes

TC400.md

File metadata and controls

29 lines (23 loc) · 689 Bytes

TC400 - Use logging '.exception' instead of 'error'

Why is it bad

Python docs point out that you should use exception method inside an exception handler. It automatically add the stack trace and logs the message as ERROR level.

How it looks like

def main_function():
    try:
        process()
        handle()
        finish()
    except Exception as ex:
        logger.error("Context message here")

How it should be

def main_function():
    try:
        process()
        handle()
        finish()
    except Exception:
        logger.exception("Context message here")