tremors 0.3.4__py3-none-any.whl → 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tremors/__init__.py +1 -1
- tremors/collector.py +4 -3
- tremors/logger.py +41 -7
- {tremors-0.3.4.dist-info → tremors-0.4.0.dist-info}/METADATA +6 -3
- tremors-0.4.0.dist-info/RECORD +10 -0
- tremors-0.3.4.dist-info/RECORD +0 -10
- {tremors-0.3.4.dist-info → tremors-0.4.0.dist-info}/WHEEL +0 -0
- {tremors-0.3.4.dist-info → tremors-0.4.0.dist-info}/licenses/LICENSE +0 -0
- {tremors-0.3.4.dist-info → tremors-0.4.0.dist-info}/top_level.txt +0 -0
tremors/__init__.py
CHANGED
tremors/collector.py
CHANGED
|
@@ -93,10 +93,11 @@ class IndentifierState(NamedTuple):
|
|
|
93
93
|
|
|
94
94
|
|
|
95
95
|
def _identifier_collect(
|
|
96
|
-
state: IndentifierState | None,
|
|
96
|
+
state: IndentifierState | None, log_item: tremors.logger.LogItem
|
|
97
97
|
) -> IndentifierState | None:
|
|
98
98
|
if state:
|
|
99
99
|
return state
|
|
100
|
+
logger = log_item.logger
|
|
100
101
|
if not logger.group_id or not logger.path:
|
|
101
102
|
return None
|
|
102
103
|
return IndentifierState(group_id=logger.group_id, parent=logger.parent, path=logger.path)
|
|
@@ -284,7 +285,7 @@ class CounterState:
|
|
|
284
285
|
step: int
|
|
285
286
|
|
|
286
287
|
|
|
287
|
-
def _counter_collect(state: CounterState, _: tremors.logger.
|
|
288
|
+
def _counter_collect(state: CounterState, _: tremors.logger.LogItem) -> CounterState:
|
|
288
289
|
state.count += state.step
|
|
289
290
|
return state
|
|
290
291
|
|
|
@@ -430,7 +431,7 @@ class ElapsedState:
|
|
|
430
431
|
t: int | None
|
|
431
432
|
|
|
432
433
|
|
|
433
|
-
def _collect_elapsed(state: ElapsedState, _: tremors.logger.
|
|
434
|
+
def _collect_elapsed(state: ElapsedState, _: tremors.logger.LogItem) -> ElapsedState:
|
|
434
435
|
t = time.perf_counter_ns()
|
|
435
436
|
if state.t0 is None:
|
|
436
437
|
state.t0 = t
|
tremors/logger.py
CHANGED
|
@@ -61,6 +61,29 @@ _current_logger: contextvars.ContextVar[Logger | None] = contextvars.ContextVar(
|
|
|
61
61
|
)
|
|
62
62
|
|
|
63
63
|
|
|
64
|
+
class LogItem(NamedTuple):
|
|
65
|
+
"""The properties of a logged message.
|
|
66
|
+
|
|
67
|
+
This is essentially the arguments passed to :meth:`Logger.log`.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
logger: Logger
|
|
71
|
+
level: int
|
|
72
|
+
msg: object
|
|
73
|
+
args: tuple[object, ...]
|
|
74
|
+
exc_info: (
|
|
75
|
+
bool
|
|
76
|
+
| tuple[type[BaseException], BaseException, TracebackType | None]
|
|
77
|
+
| tuple[None, None, None]
|
|
78
|
+
| BaseException
|
|
79
|
+
| None
|
|
80
|
+
)
|
|
81
|
+
stack_info: bool
|
|
82
|
+
stacklevel: int
|
|
83
|
+
extra: Mapping[str, object] | None
|
|
84
|
+
kwargs: dict[str, object]
|
|
85
|
+
|
|
86
|
+
|
|
64
87
|
class Collector[TState](NamedTuple):
|
|
65
88
|
"""The collector specification.
|
|
66
89
|
|
|
@@ -73,26 +96,26 @@ class Collector[TState](NamedTuple):
|
|
|
73
96
|
state: The initial state of the collector. Each time the collector
|
|
74
97
|
runs, it may update this state.
|
|
75
98
|
collect: When the collector runs, this function is called with the
|
|
76
|
-
current state, and the
|
|
99
|
+
current state, and the LogItem. It returns the new state.
|
|
77
100
|
"""
|
|
78
101
|
|
|
79
102
|
name: str
|
|
80
103
|
level: int
|
|
81
104
|
state: TState
|
|
82
|
-
collect: Callable[[TState,
|
|
105
|
+
collect: Callable[[TState, LogItem], TState]
|
|
83
106
|
|
|
84
107
|
|
|
85
108
|
def _collectors_reducer[T](
|
|
86
109
|
acc: tuple[MutableMapping[str, Collector[T]], MutableMapping[str, T]],
|
|
87
|
-
curr: tuple[
|
|
110
|
+
curr: tuple[LogItem, tuple[str, Collector[T]]],
|
|
88
111
|
) -> tuple[MutableMapping[str, Collector[T]], MutableMapping[str, T]]:
|
|
89
112
|
acc_collectors, acc_extra = acc
|
|
90
|
-
|
|
91
|
-
if curr_c.level != logging.NOTSET and level < curr_c.level:
|
|
113
|
+
log_item, (name, curr_c) = curr
|
|
114
|
+
if curr_c.level != logging.NOTSET and log_item.level < curr_c.level:
|
|
92
115
|
acc_collectors[name] = curr_c
|
|
93
116
|
acc_extra[name] = curr_c.state
|
|
94
117
|
return acc_collectors, acc_extra
|
|
95
|
-
state = curr_c.collect(curr_c.state,
|
|
118
|
+
state = curr_c.collect(curr_c.state, log_item)
|
|
96
119
|
acc_collectors[name] = Collector(curr_c.name, curr_c.level, state, curr_c.collect)
|
|
97
120
|
acc_extra[name] = state
|
|
98
121
|
return acc_collectors, acc_extra
|
|
@@ -276,9 +299,20 @@ class Logger(logging.LoggerAdapter[logging.Logger]):
|
|
|
276
299
|
"""
|
|
277
300
|
initial_collectors: MutableMapping[str, Collector[Any]] = {}
|
|
278
301
|
initial_extra: MutableMapping[str, Any] = {}
|
|
302
|
+
log_item = LogItem(
|
|
303
|
+
logger=self,
|
|
304
|
+
level=level,
|
|
305
|
+
msg=msg,
|
|
306
|
+
args=args,
|
|
307
|
+
exc_info=exc_info,
|
|
308
|
+
stack_info=stack_info,
|
|
309
|
+
stacklevel=stacklevel,
|
|
310
|
+
extra=extra,
|
|
311
|
+
kwargs=kwargs,
|
|
312
|
+
)
|
|
279
313
|
self._collectors, own_extra = functools.reduce(
|
|
280
314
|
_collectors_reducer,
|
|
281
|
-
zip(itertools.repeat(
|
|
315
|
+
zip(itertools.repeat(log_item), self._collectors.items(), strict=False),
|
|
282
316
|
(initial_collectors, initial_extra),
|
|
283
317
|
)
|
|
284
318
|
return self.logger.log(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tremors
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Tremors is a library for logging while collecting metrics.
|
|
5
5
|
Author-email: Narvin Singh <Narvin.A.Singh@gmail.com>
|
|
6
6
|
License: Tremors is a library for logging with metrics.
|
|
@@ -282,5 +282,8 @@ single logger used in both function calls maintains its state between calls.
|
|
|
282
282
|
errors=2 ERROR:root:uh-ho!
|
|
283
283
|
errors=2 INFO:root:exited: context
|
|
284
284
|
|
|
285
|
-
See the
|
|
286
|
-
collectors, and bundles.
|
|
285
|
+
See the `collector module`_ in the full `documentation`_ for how you can
|
|
286
|
+
define your own collectors, and bundles.
|
|
287
|
+
|
|
288
|
+
.. _documentation: https://tremors.readthedocs.io/en/latest
|
|
289
|
+
.. _collector module: https://tremors.readthedocs.io/en/latest/#module-tremors.collector
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
tremors/__init__.py,sha256=O_T_I0E105fnpKsuLIJncFRuzDR66qojUUFLAVthTiE,300
|
|
2
|
+
tremors/collector.py,sha256=ThaFhfh6kpIxauvlRJUi9iEzKcj_lVFJb62PNzAR654,18557
|
|
3
|
+
tremors/decorator.py,sha256=nWHwwdQBIRBU9j-zxMApLWVkqP6lrLte1-dOLhY4INY,3741
|
|
4
|
+
tremors/logger.py,sha256=kqeDEUfwVwCYgLLfftLH63onnVnVz4a7BFhNzw_36XU,12626
|
|
5
|
+
tremors/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
tremors-0.4.0.dist-info/licenses/LICENSE,sha256=X__qS-gpV601TSYqaoqkV5YKHLJlfyJ1IHbjOJbdXCw,694
|
|
7
|
+
tremors-0.4.0.dist-info/METADATA,sha256=ffaGA4qoNXPPm2ZfVryqmqdM67oS7xOeE_CZQ7CbvcQ,9823
|
|
8
|
+
tremors-0.4.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
+
tremors-0.4.0.dist-info/top_level.txt,sha256=j9lADjMU0C4UHY94-9FAQD7MHtuGDzZgSxtl_iN2kDI,8
|
|
10
|
+
tremors-0.4.0.dist-info/RECORD,,
|
tremors-0.3.4.dist-info/RECORD
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
tremors/__init__.py,sha256=3aigNRypwpHd0WDnNe7ENZw14ncu50FszuvrFaLo7Ko,300
|
|
2
|
-
tremors/collector.py,sha256=YwC5xeuovFwPoVFUD14LFmm397ypK9QlszBVpYUvcbQ,18523
|
|
3
|
-
tremors/decorator.py,sha256=nWHwwdQBIRBU9j-zxMApLWVkqP6lrLte1-dOLhY4INY,3741
|
|
4
|
-
tremors/logger.py,sha256=mnIiyHKrTtOY-1rpZF-wteB7ZlwEyeOVKKJ2E8Mnal4,11830
|
|
5
|
-
tremors/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
tremors-0.3.4.dist-info/licenses/LICENSE,sha256=X__qS-gpV601TSYqaoqkV5YKHLJlfyJ1IHbjOJbdXCw,694
|
|
7
|
-
tremors-0.3.4.dist-info/METADATA,sha256=yohMn_JIo3ecdt-b9VJBRYNTzf44TuQbIH0x1mcAEYk,9653
|
|
8
|
-
tremors-0.3.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
-
tremors-0.3.4.dist-info/top_level.txt,sha256=j9lADjMU0C4UHY94-9FAQD7MHtuGDzZgSxtl_iN2kDI,8
|
|
10
|
-
tremors-0.3.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|