Logging Patterns
There are different logs schemas depending of the microservice at this moment, they will be merge into one structural pattern for future implementations.
Analytics
The module provides a lot of functionality and flexibility. If you are unfamiliar with logging, the best way to get to grips with it is to view this Logging Cookbook.
-
Loggers expose the interface that application code directly uses.
-
Handlers send the log records (created by loggers) to the appropriate destination.
-
Filters provide a finer grained facility for determining which log records to output.
-
Formatters specify the layout of log records in the final output.
The first parameter of the log is the level of execution:
Method | Numeric Value Declaration (Code) |
---|---|
CRITICAL |
50 |
ERROR |
40 |
WARNING |
30 |
INFO |
20 |
DEBUG |
10 |
NOTSET |
0 |
The second parameter is the name of the module, when no module is selected logs point to the root directory.
The third parameter is the timestamp of the log.
The fourd parameter is the description of the error.
Note: Traceback errors correspond to python errors.
Log Snippet
INFO: root: 2023-Mar-25 04:02:55: OPTS: Get MESSAGE: collecting records from analytics database
INFO: uvicorn.error: 2023-Apr-10 13:51:09: Started server process [27464]
WARNING: uvicorn.error: 2023-Apr-10 13:55:03: Unsupported upgrade request.
ERROR: uvicorn.error: 2023-Apr-10 13:56:37: Exception in ASGI application
Traceback (most recent call last):
File "c:\users\mauro\appdata\local\programs\python\python38\lib\site-packages\uvicorn\protocols\http\httptools_impl.py", line 372, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "c:\users\mauro\appdata\local\programs\python\python38\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 75, in __call__
return await self.app(scope, receive, send)
File "c:\users\mauro\appdata\local\programs\python\python38\lib\site-packages\fastapi\applications.py", line 261, in __call__
await super().__call__(scope, receive, send)
File "c:\users\mauro\appdata\local\programs\python\python38\lib\site-packages\starlette\applications.py", line 112, in __call__
await self.middleware_stack(scope, receive, send)
File "c:\users\mauro\appdata\local\programs\python\python38\lib\site-packages\starlette\middleware\errors.py", line 181, in __call__
raise exc
File "c:\users\mauro\appdata\local\programs\python\python38\lib\site-packages\starlette\middleware\errors.py", line 159, in __call__
await self.app(scope, receive, _send)
File "c:\users\mauro\appdata\local\programs\python\python38\lib\site-packages\starlette\middleware\cors.py", line 84, in __call__
await self.app(scope, receive, send)
File "c:\users\mauro\appdata\local\programs\python\python38\lib\site-packages\starlette\exceptions.py", line 82, in __call__
raise exc
File "c:\users\mauro\appdata\local\programs\python\python38\lib\site-packages\starlette\exceptions.py", line 71, in __call__
await self.app(scope, receive, sender)
File "c:\users\mauro\appdata\local\programs\python\python38\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 21, in __call__
raise e
File "c:\users\mauro\appdata\local\programs\python\python38\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in __call__
await self.app(scope, receive, send)
File "c:\users\mauro\appdata\local\programs\python\python38\lib\site-packages\starlette\routing.py", line 656, in __call__
await route.handle(scope, receive, send)
File "c:\users\mauro\appdata\local\programs\python\python38\lib\site-packages\starlette\routing.py", line 259, in handle
await self.app(scope, receive, send)
File "c:\users\mauro\appdata\local\programs\python\python38\lib\site-packages\starlette\routing.py", line 61, in app
response = await func(request)
File "c:\users\mauro\appdata\local\programs\python\python38\lib\site-packages\fastapi\routing.py", line 227, in app
raw_response = await run_endpoint_function(
File "c:\users\mauro\appdata\local\programs\python\python38\lib\site-packages\fastapi\routing.py", line 160, in run_endpoint_function
return await dependant.call(**values)
File "C:\Users\mauro\Documents\development\dexFreight\bitbucket\loadboard-network-analytics\.\app\api\reports.py", line 56, in request_file
{ "createdAt": { "$gte": datetime.fromisoformat(date_from) } },
TypeError: fromisoformat: argument must be str
httptools.parser.errors.HttpParserCallbackError: User callback error
INFO: werkzeug: 2023-Jun-25 19:21:13: [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m
* Running on http://127.0.0.1:5000
INFO: werkzeug: 2023-Jun-25 19:21:13: [33mPress CTRL+C to quit[0m
INFO: werkzeug: 2023-Jun-25 19:21:14: * Restarting with watchdog (windowsapi)
WARNING: werkzeug: 2023-Jun-25 19:21:20: * Debugger is active!