-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(logging): enhance error logging with stack information across multiple modules #1887
refactor(logging): enhance error logging with stack information across multiple modules #1887
Conversation
β¦s multiple modules
Looks good! Could you purposefully raise some exceptions to test this out & see what the logging format is like? Temporarily adding |
{"text": "2024-11-18 07:45:47.942 | ERROR | app.auth.auth_routes:get_or_create_user:219 - Exception occurred: Self generated exception\nTraceback (most recent call last):\n\n File "", line 1, in \n File "/usr/local/lib/python3.12/multiprocessing/spawn.py", line 122, in spawn_main\n exitcode = _main(fd, parent_sentinel)\n β β β 5\n β β 8\n β <function _main at 0x7f249e1018a0>\n File "/usr/local/lib/python3.12/multiprocessing/spawn.py", line 135, in _main\n return self._bootstrap(parent_sentinel)\n β β β 5\n β β <function BaseProcess._bootstrap at 0x7f249e140180>\n β \n File "/usr/local/lib/python3.12/multiprocessing/process.py", line 314, in _bootstrap\n self.run()\n β β <function BaseProcess.run at 0x7f249e1936a0>\n β \n File "/usr/local/lib/python3.12/multiprocessing/process.py", line 108, in run\n self._target(*self._args, **self._kwargs)\n β β β β β β {'config': <uvicorn.config.Config object at 0x7f249e6b1ca0>, 'target': <bound method Server.run of <uvicorn.server.Server obj...\n β β β β β \n β β β β ()\n β β β \n β β <function subprocess_started at 0x7f249c58c860>\n β \n File "/home/appuser/.local/lib/python3.12/site-packages/uvicorn/_subprocess.py", line 80, in subprocess_started\n target(sockets=sockets)\n β β [<socket.socket fd=4, family=2, type=1, proto=0, laddr=('0.0.0.0', 8000)>]\n β <bound method Server.run of <uvicorn.server.Server object at 0x7f249e0aaf00>>\n File "/home/appuser/.local/lib/python3.12/site-packages/uvicorn/server.py", line 65, in run\n return asyncio.run(self.serve(sockets=sockets))\n β β β β β [<socket.socket fd=4, family=2, type=1, proto=0, laddr=('0.0.0.0', 8000)>]\n β β β β <function Server.serve at 0x7f249c69bc40>\n β β β <uvicorn.server.Server object at 0x7f249e0aaf00>\n β β <function run at 0x7f249e102c00>\n β <module 'asyncio' from '/usr/local/lib/python3.12/asyncio/init.py'>\n File "/usr/local/lib/python3.12/asyncio/runners.py", line 194, in run\n return runner.run(main)\n β β β <coroutine object Server.serve at 0x7f249c5e9fc0>\n β β <function Runner.run at 0x7f249e08d300>\n β <asyncio.runners.Runner object at 0x7f249eff1100>\n File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run\n return self._loop.run_until_complete(task)\n β β β β <Task pending name='Task-1' coro=<Server.serve() running at /home/appuser/.local/lib/python3.12/site-packages/uvicorn/server....\n β β β <cyfunction Loop.run_until_complete at 0x7f249c5b58a0>\n β β <uvloop.Loop running=True closed=False debug=False>\n β <asyncio.runners.Runner object at 0x7f249eff1100>\n File "/home/appuser/.local/lib/python3.12/site-packages/starlette/middleware/base.py", line 149, in coro\n await self.app(scope, receive_or_disconnect, send_no_error)\n β β β β β <function BaseHTTPMiddleware.call..call_next..send_no_error at 0x7f245c203240>\n β β β β <function BaseHTTPMiddleware.call..call_next..receive_or_disconnect at 0x7f245c1cb7e0>\n β β β {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.22.0.8', 8000), 'c...\n β β <starlette.middleware.cors.CORSMiddleware object at 0x7f245c197500>\n β <starlette.middleware.base.BaseHTTPMiddleware object at 0x7f245c381760>\n File "/home/appuser/.local/lib/python3.12/site-packages/starlette/middleware/cors.py", line 85, in call\n await self.app(scope, receive, send)\n β β β β β <function BaseHTTPMiddleware.call..call_next..send_no_error at 0x7f245c203240>\n β β β β <function BaseHTTPMiddleware.call..call_next..receive_or_disconnect at 0x7f245c1cb7e0>\n β β β {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.22.0.8', 8000), 'c...\n β β <starlette.middleware.exceptions.ExceptionMiddleware object at 0x7f245f8f15b0>\n β <starlette.middleware.cors.CORSMiddleware object at 0x7f245c197500>\n File "/home/appuser/.local/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 62, in call\n await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)\n β β β β β β β <function BaseHTTPMiddleware.call..call_next..send_no_error at 0x7f245c203240>\n β β β β β β <function BaseHTTPMiddleware.call..call_next..receive_or_disconnect at 0x7f245c1cb7e0>\n β β β β β {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.22.0.8', 8000), 'c...\n β β β β <starlette.requests.Request object at 0x7f245c1e1160>\n β β β <fastapi.routing.APIRouter object at 0x7f245ce26930>\n β β <starlette.middleware.exceptions.ExceptionMiddleware object at 0x7f245f8f15b0>\n β <function wrap_app_handling_exceptions at 0x7f248ee05d00>\n File "/home/appuser/.local/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app\n await app(scope, receive, sender)\n β β β β <function wrap_app_handling_exceptions..wrapped_app..sender at 0x7f245c22d9e0>\n β β β <function BaseHTTPMiddleware.call..call_next..receive_or_disconnect at 0x7f245c1cb7e0>\n β β {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.22.0.8', 8000), 'c...\n β <fastapi.routing.APIRouter object at 0x7f245ce26930>\n File "/home/appuser/.local/lib/python3.12/site-packages/starlette/routing.py", line 715, in call\n await self.middleware_stack(scope, receive, send)\n β β β β β <function wrap_app_handling_exceptions..wrapped_app..sender at 0x7f245c22d9e0>\n β β β β <function BaseHTTPMiddleware.call..call_next..receive_or_disconnect at 0x7f245c1cb7e0>\n β β β {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.22.0.8', 8000), 'c...\n β β <bound method Router.app of <fastapi.routing.APIRouter object at 0x7f245ce26930>>\n β <fastapi.routing.APIRouter object at 0x7f245ce26930>\n File "/home/appuser/.local/lib/python3.12/site-packages/starlette/routing.py", line 735, in app\n await route.handle(scope, receive, send)\n β β β β β <function wrap_app_handling_exceptions..wrapped_app..sender at 0x7f245c22d9e0>\n β β β β <function BaseHTTPMiddleware.call..call_next..receive_or_disconnect at 0x7f245c1cb7e0>\n β β β {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.22.0.8', 8000), 'c...\n β β <function Route.handle at 0x7f248ee07240>\n β APIRoute(path='/auth/me/', name='my_data', methods=['GET'])\n File "/home/appuser/.local/lib/python3.12/site-packages/starlette/routing.py", line 288, in handle\n await self.app(scope, receive, send)\n β β β β β <function wrap_app_handling_exceptions..wrapped_app..sender at 0x7f245c22d9e0>\n β β β β <function BaseHTTPMiddleware.call..call_next..receive_or_disconnect at 0x7f245c1cb7e0>\n β β β {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.22.0.8', 8000), 'c...\n β β <function request_response..app at 0x7f245c4265c0>\n β APIRoute(path='/auth/me/', name='my_data', methods=['GET'])\n File "/home/appuser/.local/lib/python3.12/site-packages/starlette/routing.py", line 76, in app\n await wrap_app_handling_exceptions(app, request)(scope, receive, send)\n β This is a sample log that was generated locally using self generated exception in fmtm.json file. |
Related Issue
Resolves #1756
Describe this PR
Replaced log.error with log.exception and included traceback information where exceptions are raised.
Checklist before requesting a review