{"id":915,"hash":"88ddc2de9f85091644969da8a856e0aa37bfb15320dae37fed9f7535754241c6","pattern":"FastAPI uvicorn not logging errors","full_message":"I am learning fastapi, and I am starting a uvicorn server on localhost. Whenever there is an error or an exception, I am not getting the traceback.\nAll I am getting is : INFO:     127.0.0.1:56914 - \"POST /create/user/ HTTP/1.1\" 500 Internal Server Error\n\nSo, It is difficult to debug, I am trying out logging module of python\n\n import logging\n log = logging.getLogger(\"uvicorn\")\n log.setLevel(logging.DEBUG)\n\nI have also tried starting uvicorn with debug parameter\n\nif __name__ == \"__main__\":\n    dev = 1\n    print(\"printing\")\n    if dev == 1:\n        uvicorn.run('main:app', host=\"127.0.0.1\", port=5000, log_level=\"info\", reload=True, debug=True)\n    if dev == 2:\n        uvicorn.run('main:app', host=\"127.0.0.1\", port=5000, log_level=\"info\", workers=2)\n\nstill the same problem persists. I am in development phase and I need the error traceback, please guide.","ecosystem":"pypi","package_name":"logging","package_version":null,"solution":"Solution / Fix\nNow, when you execute uvicorn by the in-Python command uvicorn.run(app), this is your next move:\n\ntake the ucivorn default logging config and add the handler from your application to it:\n\nconfig = {}\n\n# this is default (site-packages\\uvicorn\\main.py)\nconfig['log_config'] = \"{\n   \"version\":1,\n   \"disable_existing_loggers\":true,\n   \"formatters\":{\n      \"default\":{\n         \"()\":\"uvicorn.logging.DefaultFormatter\",\n         \"fmt\":\"%(levelprefix)s %(message)s\",\n         \"use_colors\":\"None\"\n      },\n      \"access\":{\n         \"()\":\"uvicorn.logging.AccessFormatter\",\n         \"fmt\":\"%(levelprefix)s %(client_addr)s - \\\"%(request_line)s\\\" %(status_code)s\"\n      }\n   },\n   \"handlers\":{\n      \"default\":{\n         \"formatter\":\"default\",\n         \"class\":\"logging.StreamHandler\",\n         \"stream\":\"ext://sys.stderr\"\n      },\n      \"access\":{\n         \"formatter\":\"access\",\n         \"class\":\"logging.StreamHandler\",\n         \"stream\":\"ext://sys.stdout\"\n      }\n   },\n   \"loggers\":{\n      \"uvicorn\":{\n         \"handlers\":[\n            \"default\"\n         ],\n         \"level\":\"INFO\"\n      },\n      \"uvicorn.error\":{\n         \"level\":\"INFO\",\n         \"handlers\":[\n            \"default\"\n         ],\n         \"propagate\":true\n      },\n      \"uvicorn.access\":{\n         \"handlers\":[\n            \"access\"\n         ],\n         \"level\":\"INFO\",\n         \"propagate\":false\n      }\n   }\n}\n\n# add your handler to it (in my case, I'm working with quart, but you can do this with Flask etc. as well, they're all the same)\nconfig['log_config']['loggers']['quart'] = \n{\n   \"handlers\":[\n      \"default\"\n   ],\n   \"level\":\"INFO\"\n}\n\nthis will keep the logger from quart/Flask/etc. enabled when uvicorn starts. Alternatively, you can set disable_existing_loggers to False. But this will keep all loggers enabled and then you will probable get more messages than you wish.\n\nFinally, pass the config to uvicorn:\n\nuvicorn.run(app, **config)\n\nExplanation\nWhen uvicorn's logging config has set disable_existing_loggers to True, all other loggers will be disabled. This also means that the logger quart and Flask use (which prints the traceback) get disabled. You can either set the config to NOT disable other loggers, or re-add them to the config so uvicorn doesn't disable them in the first place.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/66602480/fastapi-uvicorn-not-logging-errors","votes":25,"created_at":"2026-04-19T04:51:59.338422+00:00","updated_at":"2026-04-19T04:51:59.338422+00:00"}