tremors 0.3.5__tar.gz → 0.4.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tremors
3
- Version: 0.3.5
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.
@@ -5,6 +5,6 @@ from tremors.logger import EXTRA_KEY, Collector, Logger
5
5
 
6
6
  __authors__ = ["Narvin Singh"]
7
7
  __project__ = "Tremors"
8
- __version__ = "0.3.5"
8
+ __version__ = "0.4.0"
9
9
 
10
10
  __all__ = ["EXTRA_KEY", "Collector", "Logger", "__version__", "from_logged", "logged"]
@@ -93,10 +93,11 @@ class IndentifierState(NamedTuple):
93
93
 
94
94
 
95
95
  def _identifier_collect(
96
- state: IndentifierState | None, logger: tremors.logger.Logger
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.Logger) -> CounterState:
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.Logger) -> ElapsedState:
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
@@ -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 logger. It returns the new state.
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, Logger], 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[tuple[Logger, int], tuple[str, Collector[T]]],
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
- (logger, level), (name, curr_c) = curr
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, logger)
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((self, level)), self._collectors.items(), strict=False),
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.5
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.
File without changes
File without changes
File without changes
File without changes
File without changes