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
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@
9
9
3. add `morebuiltins.logs.LogHelper` to quickly bind a logging handler to a logger, with a StreamHandler or SizedTimedRotatingFileHandler.
10
10
4.**Compatibility Warnings**:
11
11
1. move `async_logger`, `AsyncQueueListener`, `LogHelper`, `RotatingFileWriter`, and `SizedTimedRotatingFileHandler` from `morebuiltins.funcs` to `morebuiltins.logs`.
12
+
5. add `ContextFilter` for logging, to add context variables to log records.
12
13
13
14
### 1.3.1 (2025-06-19)
14
15
1. add `check_recursion` to `morebuiltins.funcs`, to check if a function is recursive.
Copy file name to clipboardExpand all lines: README.md
+15Lines changed: 15 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -275,6 +275,21 @@ print(morebuiltins.__file__)
275
275
18.2 `SharedBytes` - Shared Memory for Python, for python 3.8+.
276
276
277
277
278
+
## 19. morebuiltins.logs
279
+
280
+
19.1 `async_logger` - Asynchronous non-blocking QueueListener that manages logger handlers.
281
+
282
+
19.2 `AsyncQueueListener` - Asynchronous non-blocking QueueListener that manages logger handlers.
283
+
284
+
19.3 `LogHelper` - Quickly bind a logging handler to a logger, with a StreamHandler or SizedTimedRotatingFileHandler.
285
+
286
+
19.4 `RotatingFileWriter` - RotatingFileWriter class for writing to a file with rotation support.
287
+
288
+
19.5 `SizedTimedRotatingFileHandler` - TimedRotatingFileHandler with maxSize, to avoid files that are too large.
289
+
290
+
19.6 `ContextFilter` - A logging filter that injects context variables into extra of log records. ContextVar is used to manage context-specific data in a thread-safe / async-safe manner.
19.6`ContextFilter`- A logging filter that injects context variables into extra of log records. ContextVar is used to manage context-specific data in a thread-safe /async-safe manner.
2893
+
2894
+
2895
+
```python
2896
+
RequestID / TraceID / TaskID can be used to trace logs belonging to the same request or operation across different threads orasync tasks.
2897
+
2898
+
Example::
2899
+
2900
+
import random
2901
+
import time
2902
+
import typing
2903
+
from concurrent.futures import ThreadPoolExecutor
2904
+
from contextvars import ContextVar
2905
+
from logging import Filter, Formatter, StreamHandler, getLogger
2906
+
from threading import current_thread
2907
+
2908
+
def test(trace_id: int=0):
2909
+
trace_id_var.set(trace_id)
2910
+
for _ inrange(3):
2911
+
time.sleep(random.random())
2912
+
logger.debug(f"msg from thread: {current_thread().ident}")
"""A logging filter that injects context variables into extra of log records. ContextVar is used to manage context-specific data in a thread-safe / async-safe manner.
702
+
RequestID / TraceID / TaskID can be used to trace logs belonging to the same request or operation across different threads or async tasks.
703
+
704
+
Example::
705
+
706
+
import random
707
+
import time
708
+
import typing
709
+
from concurrent.futures import ThreadPoolExecutor
710
+
from contextvars import ContextVar
711
+
from logging import Filter, Formatter, StreamHandler, getLogger
712
+
from threading import current_thread
713
+
714
+
def test(trace_id: int = 0):
715
+
trace_id_var.set(trace_id)
716
+
for _ in range(3):
717
+
time.sleep(random.random())
718
+
logger.debug(f"msg from thread: {current_thread().ident}")
0 commit comments