tremors 0.3.5__tar.gz → 0.4.1__tar.gz
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-0.3.5/src/tremors.egg-info → tremors-0.4.1}/PKG-INFO +3 -2
- {tremors-0.3.5 → tremors-0.4.1}/pyproject.toml +5 -1
- {tremors-0.3.5 → tremors-0.4.1}/src/tremors/__init__.py +1 -1
- {tremors-0.3.5 → tremors-0.4.1}/src/tremors/collector.py +7 -13
- {tremors-0.3.5 → tremors-0.4.1}/src/tremors/decorator.py +2 -7
- {tremors-0.3.5 → tremors-0.4.1}/src/tremors/logger.py +44 -16
- {tremors-0.3.5 → tremors-0.4.1/src/tremors.egg-info}/PKG-INFO +3 -2
- {tremors-0.3.5 → tremors-0.4.1}/src/tremors.egg-info/requires.txt +2 -1
- {tremors-0.3.5 → tremors-0.4.1}/LICENSE +0 -0
- {tremors-0.3.5 → tremors-0.4.1}/README.rst +0 -0
- {tremors-0.3.5 → tremors-0.4.1}/setup.cfg +0 -0
- {tremors-0.3.5 → tremors-0.4.1}/src/tremors/py.typed +0 -0
- {tremors-0.3.5 → tremors-0.4.1}/src/tremors.egg-info/SOURCES.txt +0 -0
- {tremors-0.3.5 → tremors-0.4.1}/src/tremors.egg-info/dependency_links.txt +0 -0
- {tremors-0.3.5 → tremors-0.4.1}/src/tremors.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tremors
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.1
|
|
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.
|
|
@@ -31,9 +31,10 @@ Requires-Python: >=3.12
|
|
|
31
31
|
Description-Content-Type: text/x-rst
|
|
32
32
|
License-File: LICENSE
|
|
33
33
|
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: coverage~=7.11; extra == "dev"
|
|
34
35
|
Requires-Dist: mypy~=1.18; extra == "dev"
|
|
35
36
|
Requires-Dist: pre-commit~=4.3; extra == "dev"
|
|
36
|
-
Requires-Dist: pytest~=
|
|
37
|
+
Requires-Dist: pytest~=9.0; extra == "dev"
|
|
37
38
|
Requires-Dist: ruff~=0.14.2; extra == "dev"
|
|
38
39
|
Requires-Dist: sphinx-lint~=1.0; extra == "dev"
|
|
39
40
|
Requires-Dist: yamllint~=1.37; extra == "dev"
|
|
@@ -24,9 +24,10 @@ dependencies = [
|
|
|
24
24
|
|
|
25
25
|
[project.optional-dependencies]
|
|
26
26
|
dev = [
|
|
27
|
+
"coverage ~= 7.11",
|
|
27
28
|
"mypy ~= 1.18",
|
|
28
29
|
"pre-commit ~= 4.3",
|
|
29
|
-
"pytest ~=
|
|
30
|
+
"pytest ~= 9.0",
|
|
30
31
|
"ruff ~= 0.14.2",
|
|
31
32
|
"sphinx-lint ~= 1.0",
|
|
32
33
|
"yamllint ~= 1.37",
|
|
@@ -52,6 +53,9 @@ package-data = {"*" = ["py.typed"]}
|
|
|
52
53
|
[tool.setuptools.dynamic]
|
|
53
54
|
version = {attr = "tremors.__version__"}
|
|
54
55
|
|
|
56
|
+
[tool.coverage.run]
|
|
57
|
+
omit = ["test/*"]
|
|
58
|
+
|
|
55
59
|
[tool.mypy]
|
|
56
60
|
python_version = "3.14"
|
|
57
61
|
strict = true
|
|
@@ -14,20 +14,13 @@ fixed signature as described in :class:`Formatter`.
|
|
|
14
14
|
|
|
15
15
|
import dataclasses
|
|
16
16
|
import logging
|
|
17
|
-
import sys
|
|
18
17
|
import time
|
|
19
|
-
|
|
20
|
-
from
|
|
18
|
+
import uuid # noqa: TC003
|
|
19
|
+
from collections.abc import Callable, Mapping
|
|
20
|
+
from typing import NamedTuple, Protocol
|
|
21
21
|
|
|
22
22
|
import tremors.logger
|
|
23
23
|
|
|
24
|
-
if TYPE_CHECKING:
|
|
25
|
-
import uuid
|
|
26
|
-
from collections.abc import Callable
|
|
27
|
-
elif "sphinx" in sys.modules:
|
|
28
|
-
import uuid # noqa: TC003
|
|
29
|
-
from collections.abc import Callable
|
|
30
|
-
|
|
31
24
|
|
|
32
25
|
def get_state[T](typ: type[T], name: str, record: logging.LogRecord) -> T | None:
|
|
33
26
|
"""Get the collector state from a :class:`~logging.LogRecord`.
|
|
@@ -93,10 +86,11 @@ class IndentifierState(NamedTuple):
|
|
|
93
86
|
|
|
94
87
|
|
|
95
88
|
def _identifier_collect(
|
|
96
|
-
state: IndentifierState | None,
|
|
89
|
+
state: IndentifierState | None, log_item: tremors.logger.LogItem
|
|
97
90
|
) -> IndentifierState | None:
|
|
98
91
|
if state:
|
|
99
92
|
return state
|
|
93
|
+
logger = log_item.logger
|
|
100
94
|
if not logger.group_id or not logger.path:
|
|
101
95
|
return None
|
|
102
96
|
return IndentifierState(group_id=logger.group_id, parent=logger.parent, path=logger.path)
|
|
@@ -284,7 +278,7 @@ class CounterState:
|
|
|
284
278
|
step: int
|
|
285
279
|
|
|
286
280
|
|
|
287
|
-
def _counter_collect(state: CounterState, _: tremors.logger.
|
|
281
|
+
def _counter_collect(state: CounterState, _: tremors.logger.LogItem) -> CounterState:
|
|
288
282
|
state.count += state.step
|
|
289
283
|
return state
|
|
290
284
|
|
|
@@ -430,7 +424,7 @@ class ElapsedState:
|
|
|
430
424
|
t: int | None
|
|
431
425
|
|
|
432
426
|
|
|
433
|
-
def _collect_elapsed(state: ElapsedState, _: tremors.logger.
|
|
427
|
+
def _collect_elapsed(state: ElapsedState, _: tremors.logger.LogItem) -> ElapsedState:
|
|
434
428
|
t = time.perf_counter_ns()
|
|
435
429
|
if state.t0 is None:
|
|
436
430
|
state.t0 = t
|
|
@@ -5,13 +5,8 @@ and injects that logger into the callable.
|
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
import functools
|
|
8
|
-
import
|
|
9
|
-
from typing import
|
|
10
|
-
|
|
11
|
-
if TYPE_CHECKING:
|
|
12
|
-
from collections.abc import Callable
|
|
13
|
-
elif "sphinx" in sys.modules:
|
|
14
|
-
from collections.abc import Callable # noqa: TC003
|
|
8
|
+
from collections.abc import Callable # noqa: TC003
|
|
9
|
+
from typing import Any, cast, overload
|
|
15
10
|
|
|
16
11
|
import tremors.logger
|
|
17
12
|
|
|
@@ -45,22 +45,39 @@ import contextvars
|
|
|
45
45
|
import functools
|
|
46
46
|
import itertools
|
|
47
47
|
import logging
|
|
48
|
-
import sys
|
|
49
48
|
import uuid
|
|
50
|
-
from
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
from collections.abc import Callable, Mapping, MutableMapping
|
|
54
|
-
from types import TracebackType
|
|
55
|
-
elif "sphinx" in sys.modules:
|
|
56
|
-
from collections.abc import Callable, Mapping # noqa: TC003
|
|
57
|
-
from types import TracebackType # noqa: TC003
|
|
49
|
+
from collections.abc import Callable, Mapping, MutableMapping # noqa: TC003
|
|
50
|
+
from types import TracebackType # noqa: TC003
|
|
51
|
+
from typing import Any, NamedTuple, Self
|
|
58
52
|
|
|
59
53
|
_current_logger: contextvars.ContextVar[Logger | None] = contextvars.ContextVar(
|
|
60
54
|
"_current_logger", default=None
|
|
61
55
|
)
|
|
62
56
|
|
|
63
57
|
|
|
58
|
+
class LogItem(NamedTuple):
|
|
59
|
+
"""The properties of a logged message.
|
|
60
|
+
|
|
61
|
+
This is essentially the arguments passed to :meth:`Logger.log`.
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
logger: Logger
|
|
65
|
+
level: int
|
|
66
|
+
msg: object
|
|
67
|
+
args: tuple[object, ...]
|
|
68
|
+
exc_info: (
|
|
69
|
+
bool
|
|
70
|
+
| tuple[type[BaseException], BaseException, TracebackType | None]
|
|
71
|
+
| tuple[None, None, None]
|
|
72
|
+
| BaseException
|
|
73
|
+
| None
|
|
74
|
+
)
|
|
75
|
+
stack_info: bool
|
|
76
|
+
stacklevel: int
|
|
77
|
+
extra: Mapping[str, object] | None
|
|
78
|
+
kwargs: dict[str, object]
|
|
79
|
+
|
|
80
|
+
|
|
64
81
|
class Collector[TState](NamedTuple):
|
|
65
82
|
"""The collector specification.
|
|
66
83
|
|
|
@@ -73,26 +90,26 @@ class Collector[TState](NamedTuple):
|
|
|
73
90
|
state: The initial state of the collector. Each time the collector
|
|
74
91
|
runs, it may update this state.
|
|
75
92
|
collect: When the collector runs, this function is called with the
|
|
76
|
-
current state, and the
|
|
93
|
+
current state, and the LogItem. It returns the new state.
|
|
77
94
|
"""
|
|
78
95
|
|
|
79
96
|
name: str
|
|
80
97
|
level: int
|
|
81
98
|
state: TState
|
|
82
|
-
collect: Callable[[TState,
|
|
99
|
+
collect: Callable[[TState, LogItem], TState]
|
|
83
100
|
|
|
84
101
|
|
|
85
102
|
def _collectors_reducer[T](
|
|
86
103
|
acc: tuple[MutableMapping[str, Collector[T]], MutableMapping[str, T]],
|
|
87
|
-
curr: tuple[
|
|
104
|
+
curr: tuple[LogItem, tuple[str, Collector[T]]],
|
|
88
105
|
) -> tuple[MutableMapping[str, Collector[T]], MutableMapping[str, T]]:
|
|
89
106
|
acc_collectors, acc_extra = acc
|
|
90
|
-
|
|
91
|
-
if curr_c.level != logging.NOTSET and level < curr_c.level:
|
|
107
|
+
log_item, (name, curr_c) = curr
|
|
108
|
+
if curr_c.level != logging.NOTSET and log_item.level < curr_c.level:
|
|
92
109
|
acc_collectors[name] = curr_c
|
|
93
110
|
acc_extra[name] = curr_c.state
|
|
94
111
|
return acc_collectors, acc_extra
|
|
95
|
-
state = curr_c.collect(curr_c.state,
|
|
112
|
+
state = curr_c.collect(curr_c.state, log_item)
|
|
96
113
|
acc_collectors[name] = Collector(curr_c.name, curr_c.level, state, curr_c.collect)
|
|
97
114
|
acc_extra[name] = state
|
|
98
115
|
return acc_collectors, acc_extra
|
|
@@ -276,9 +293,20 @@ class Logger(logging.LoggerAdapter[logging.Logger]):
|
|
|
276
293
|
"""
|
|
277
294
|
initial_collectors: MutableMapping[str, Collector[Any]] = {}
|
|
278
295
|
initial_extra: MutableMapping[str, Any] = {}
|
|
296
|
+
log_item = LogItem(
|
|
297
|
+
logger=self,
|
|
298
|
+
level=level,
|
|
299
|
+
msg=msg,
|
|
300
|
+
args=args,
|
|
301
|
+
exc_info=exc_info,
|
|
302
|
+
stack_info=stack_info,
|
|
303
|
+
stacklevel=stacklevel,
|
|
304
|
+
extra=extra,
|
|
305
|
+
kwargs=kwargs,
|
|
306
|
+
)
|
|
279
307
|
self._collectors, own_extra = functools.reduce(
|
|
280
308
|
_collectors_reducer,
|
|
281
|
-
zip(itertools.repeat(
|
|
309
|
+
zip(itertools.repeat(log_item), self._collectors.items(), strict=False),
|
|
282
310
|
(initial_collectors, initial_extra),
|
|
283
311
|
)
|
|
284
312
|
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.1
|
|
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.
|
|
@@ -31,9 +31,10 @@ Requires-Python: >=3.12
|
|
|
31
31
|
Description-Content-Type: text/x-rst
|
|
32
32
|
License-File: LICENSE
|
|
33
33
|
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: coverage~=7.11; extra == "dev"
|
|
34
35
|
Requires-Dist: mypy~=1.18; extra == "dev"
|
|
35
36
|
Requires-Dist: pre-commit~=4.3; extra == "dev"
|
|
36
|
-
Requires-Dist: pytest~=
|
|
37
|
+
Requires-Dist: pytest~=9.0; extra == "dev"
|
|
37
38
|
Requires-Dist: ruff~=0.14.2; extra == "dev"
|
|
38
39
|
Requires-Dist: sphinx-lint~=1.0; extra == "dev"
|
|
39
40
|
Requires-Dist: yamllint~=1.37; extra == "dev"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|