You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Chromatrace is a Python package designed for advanced logging capabilities, including trace and request ID management. It provides a flexible logging configuration and supports colored logging for better visibility.
16
+
Chromatrace is a Python package designed for advanced logging capabilities, including trace and request ID management along with process ID. It provides a flexible logging configuration and supports colored logging for better visibility.
17
17
18
18
I believe that logging is an essential part of any application, and it is crucial to have a well-organized and structured logging system. Chromatrace aims to provide a simple and easy-to-use logging system that can be integrated into any Python application.
19
19
In simple terms, Chromatrace is a Best Practice of Logging in Python.
@@ -23,8 +23,13 @@ In simple terms, Chromatrace is a Best Practice of Logging in Python.
23
23
- Configurable logging settings using Pydantic.
24
24
- Customizable log levels and loggers for different services.
25
25
- Support for trace IDs and request IDs.
26
+
- Support for process IDs.
26
27
- Customizable log formats and handlers.
27
28
- Asynchronous and synchronous function tracing.
29
+
- Uvicorn integration for logging configuration to customize log settings.
30
+
- FastAPI integration for request ID management.
31
+
- SocketIO integration for request ID management.
32
+
- Practical examples for different frameworks and use cases.
28
33
29
34
## Installation
30
35
@@ -76,13 +81,13 @@ container = Container()
76
81
77
82
from chromatrace import LoggingConfig, LoggingSettings
@@ -195,6 +200,48 @@ Received message on main namespace. SID: FI3E_S_A-KsTi4RLAAAD, Message: Hello fr
195
200
Yes, the socket logs are also within the trace. The trace ID - `S-4e2b7c5e` and `S-aaf46528` was added to the log messages. For better experience, the prefix `S` was added to the trace ID to differentiate it from the request ID.
196
201
197
202
203
+
### Uvicorn Integration
204
+
205
+
```python
206
+
from chromatrace.uvicorn import GetLoggingConfig, UvicornLoggingSettings
207
+
208
+
rest_application = FastAPI()
209
+
210
+
uvicorn.run(
211
+
rest_application,
212
+
host="0.0.0.0",
213
+
port=8000,
214
+
log_level="debug",
215
+
log_config=GetLoggingConfig(
216
+
UvicornLoggingSettings(
217
+
enable_file_logging=True,
218
+
show_process_id=True,
219
+
)
220
+
),
221
+
)
222
+
```
223
+
224
+
Result:
225
+
```log
226
+
(2024-12-12 20:54:54)-[PID:3710345]-[INFO]: Started server process [3710345]
227
+
(2024-12-12 20:54:54)-[PID:3710345]-[INFO]: Waiting for application startup.
(2024-12-12 21:16:45)-[PID:3710345]-[INFO]: Finished server process [3710345]
240
+
```
241
+
242
+
The logs are within the process ID - `PID:3710345` was added to the log messages. The log messages are also colored for better visibility. The log messages are also written to the file if the `enable_file_logging` is set to `True`. For more information, check the [config.py](src/chromatrace/uvicorn/config.py) file, `UvicornLoggingSettings` class.
243
+
244
+
198
245
## Examples
199
246
200
247
> You don't trust me, do you? I understand. You wanna see it in action, right? I got you covered. :)
0 commit comments