Skip to content

Commit b9af8b2

Browse files
committed
docs: Update README.md with badges and SocketIO integration examples
1 parent beb05be commit b9af8b2

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

Diff for: README.md

+53-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
# Chromatrace
2+
---
3+
[![GitHub](https://img.shields.io/github/license/Msameim181/Python-Logging-Best-Practice.svg)]()
4+
[![Version](https://badge.fury.io/gh/Msameim181%2FPython-Logging-Best-Practice.svg)](https://badge.fury.io/gh/Msameim181%2FPython-Logging-Best-Practice)
5+
[![GitHub Release](https://img.shields.io/github/release/Msameim181/Python-Logging-Best-Practice.svg?style=flat)]()
6+
[![GitHub Release Date](https://img.shields.io/github/release-date/Msameim181/Python-Logging-Best-Practice.svg?style=flat)]()
7+
[![GitHub Release Date](https://img.shields.io/github/last-commit/Msameim181/Python-Logging-Best-Practice.svg?style=flat)]()
8+
[![GitHub issues](https://img.shields.io/github/issues/Msameim181/Python-Logging-Best-Practice.svg)]()
9+
10+
[![PyPi Version](https://img.shields.io/pypi/v/chromatrace.svg)](https://pypi.python.org/pypi/chromatrace/)
11+
[![PyPi Version Alt](https://badge.fury.io/py/chromatrace.svg)](https://pypi.python.org/pypi/chromatrace/)
12+
![PyPI Downloads](https://static.pepy.tech/badge/chromatrace)
13+
[![Python Versions](https://img.shields.io/pypi/pyversions/chromatrace.svg)]()
14+
215

316
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.
417

@@ -153,9 +166,38 @@ Something went wrong in second service
153166
As you can see, the request ID - `R-ffe0a9a2` is automatically added to the log messages from the thread that handles the request.
154167

155168

169+
### SocketIO Integration
170+
171+
```python
172+
from chromatrace import SocketRequestIdMiddleware
173+
174+
socket_application = SocketRequestIdMiddleware(socket_application)
175+
```
176+
The full example can be found in the [socket_app.py](src/examples/socket_app.py) file. I recommend you to check it out before making any decision. The client-side code can be found in the [socket_client.py](src/examples/socket_client.py) file.
177+
178+
Result:
179+
```log
180+
[S-4e2b7c5e]-[Development]-(2024-12-06 01:15:18)-[INFO]-[Socket]-FILENAME:socket_app.py-FUNC:connect-THREAD:MainThread-LINE:86 ::
181+
Socket connected on main namespace. SID: wB-srwnv9Xa2w_8bAAAB
182+
183+
[S-4e2b7c5e]-[Development]-(2024-12-06 01:15:20)-[INFO]-[Socket]-FILENAME:socket_app.py-FUNC:message-THREAD:MainThread-LINE:90 ::
184+
Received message on main namespace. SID: wB-srwnv9Xa2w_8bAAAB, Message: Hello from the client
185+
186+
[S-aaf46528]-[Development]-(2024-12-06 01:15:47)-[INFO]-[Socket]-FILENAME:socket_app.py-FUNC:connect-THREAD:MainThread-LINE:86 ::
187+
Socket connected on main namespace. SID: FI3E_S_A-KsTi4RLAAAD
188+
189+
[S-aaf46528]-[Development]-(2024-12-06 01:15:49)-[INFO]-[Socket]-FILENAME:socket_app.py-FUNC:message-THREAD:MainThread-LINE:90 ::
190+
Received message on main namespace. SID: FI3E_S_A-KsTi4RLAAAD, Message: Hello from the client
191+
```
192+
193+
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.
194+
195+
156196
## Examples
157197

158-
You can find examples of how to use Chromatrace in the [examples](src/exmples/) directory. Run the examples using the following command:
198+
> You don't trust me, do you? I understand. You wanna see it in action, right? I got you covered. :)
199+
200+
You can find examples of how to use Chromatrace in the [examples](src/examples/) directory. Run the examples using the following command:
159201

160202
```bash
161203
python main.py
@@ -167,7 +209,16 @@ Then, run:
167209
curl 0.0.0.0:8000
168210
```
169211

170-
Now, check the logs in the terminal. :)
212+
Now, check the logs in the terminal.
213+
214+
Also, the socket server will start and wait for the client to connect on `http://localhost:8001`.
215+
For socket client-side run the following command in another terminal:
216+
217+
```bash
218+
python socket_client.py
219+
```
220+
221+
Now, check the logs in the both terminal.
171222

172223
## License
173224

0 commit comments

Comments
 (0)