logger-36 2023.13__py3-none-any.whl → 2024.2__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.
Files changed (41) hide show
  1. logger_36/__init__.py +3 -6
  2. logger_36/catalog/config/console_rich.py +49 -0
  3. logger_36/catalog/handler/console.py +80 -0
  4. logger_36/{type/console.py → catalog/handler/console_rich.py} +77 -52
  5. logger_36/catalog/handler/file.py +90 -0
  6. logger_36/catalog/handler/generic.py +150 -0
  7. logger_36/catalog/logging/chronos.py +39 -0
  8. logger_36/catalog/logging/gpu.py +58 -0
  9. logger_36/catalog/logging/memory.py +105 -0
  10. logger_36/catalog/logging/system.py +62 -0
  11. logger_36/config/issue.py +32 -0
  12. logger_36/config/memory.py +33 -0
  13. logger_36/config/message.py +48 -0
  14. logger_36/{config.py → config/system.py} +0 -17
  15. logger_36/constant/generic.py +37 -0
  16. logger_36/constant/handler.py +35 -0
  17. logger_36/constant/issue.py +35 -0
  18. logger_36/{type/file.py → constant/logger.py} +13 -15
  19. logger_36/constant/memory.py +39 -0
  20. logger_36/{constant.py → constant/message.py} +11 -20
  21. logger_36/constant/record.py +35 -0
  22. logger_36/constant/system.py +39 -0
  23. logger_36/instance.py +34 -0
  24. logger_36/main.py +133 -124
  25. logger_36/{measure → task/format}/memory.py +35 -27
  26. logger_36/task/format/message.py +112 -0
  27. logger_36/task/format/rule.py +47 -0
  28. logger_36/task/inspection.py +18 -18
  29. logger_36/{measure → task/measure}/chronos.py +4 -2
  30. logger_36/task/measure/memory.py +50 -0
  31. logger_36/task/storage.py +144 -0
  32. logger_36/type/extension.py +73 -61
  33. logger_36/type/issue.py +57 -0
  34. logger_36/type/logger.py +349 -0
  35. logger_36/version.py +1 -1
  36. {logger_36-2023.13.dist-info → logger_36-2024.2.dist-info}/METADATA +1 -2
  37. logger_36-2024.2.dist-info/RECORD +39 -0
  38. {logger_36-2023.13.dist-info → logger_36-2024.2.dist-info}/WHEEL +1 -1
  39. logger_36/type/generic.py +0 -116
  40. logger_36-2023.13.dist-info/RECORD +0 -16
  41. {logger_36-2023.13.dist-info → logger_36-2024.2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,349 @@
1
+ # Copyright CNRS/Inria/UCA
2
+ # Contributor(s): Eric Debreuve (since 2023)
3
+ #
4
+ # eric.debreuve@cnrs.fr
5
+ #
6
+ # This software is governed by the CeCILL license under French law and
7
+ # abiding by the rules of distribution of free software. You can use,
8
+ # modify and/ or redistribute the software under the terms of the CeCILL
9
+ # license as circulated by CEA, CNRS and INRIA at the following URL
10
+ # "http://www.cecill.info".
11
+ #
12
+ # As a counterpart to the access to the source code and rights to copy,
13
+ # modify and redistribute granted by the license, users are provided only
14
+ # with a limited warranty and the software's author, the holder of the
15
+ # economic rights, and the successive licensors have only limited
16
+ # liability.
17
+ #
18
+ # In this respect, the user's attention is drawn to the risks associated
19
+ # with loading, using, modifying and/or developing or reproducing the
20
+ # software by the user in light of its specific status of free software,
21
+ # that may mean that it is complicated to manipulate, and that also
22
+ # therefore means that it is reserved for developers and experienced
23
+ # professionals having in-depth computer knowledge. Users are therefore
24
+ # encouraged to load and test the software's suitability as regards their
25
+ # requirements in conditions enabling the security of their systems and/or
26
+ # data to be ensured and, more generally, to use and operate it in the
27
+ # same conditions as regards security.
28
+ #
29
+ # The fact that you are presently reading this means that you have had
30
+ # knowledge of the CeCILL license and that you accept its terms.
31
+
32
+ from __future__ import annotations
33
+
34
+ import dataclasses as dtcl
35
+ import logging as lggg
36
+ import sys as sstm
37
+ import types as t
38
+ import typing as h
39
+ from datetime import datetime as dttm
40
+ from pathlib import Path as path_t
41
+ from traceback import TracebackException as traceback_t
42
+
43
+ from logger_36.config.message import DATE_FORMAT, INTERCEPTED_LOG_SEPARATOR
44
+ from logger_36.constant.generic import NOT_PASSED
45
+ from logger_36.constant.issue import ORDER, order_h
46
+ from logger_36.constant.logger import (
47
+ HIDE_WHERE_KWARG,
48
+ LOGGER_NAME,
49
+ WARNING_LOGGER_NAME,
50
+ WARNING_TYPE_COMPILED_PATTERN,
51
+ logger_handle_h,
52
+ )
53
+ from logger_36.constant.record import SHOW_MEMORY_ATTR, SHOW_W_RULE_ATTR
54
+ from logger_36.task.format.memory import (
55
+ FormattedUsageWithAutoUnit as FormattedMemoryUsage,
56
+ )
57
+ from logger_36.task.format.message import FormattedMessage
58
+ from logger_36.task.measure.chronos import ElapsedTime
59
+ from logger_36.task.measure.memory import CurrentUsage as CurrentMemoryUsage
60
+ from logger_36.type.issue import NewIssue, issue_t
61
+
62
+
63
+ @dtcl.dataclass(slots=True, repr=False, eq=False)
64
+ class logger_t(lggg.Logger):
65
+ ISSUE_CONTEXT_SEPARATOR: h.ClassVar[str] = ">"
66
+ ISSUE_CONTEXT_END: h.ClassVar[str] = ":: "
67
+
68
+ # Must not be False until at least one handler has been added.
69
+ should_hold_messages: bool = True
70
+
71
+ name: dtcl.InitVar[str] = LOGGER_NAME
72
+ level: dtcl.InitVar[int] = lggg.NOTSET
73
+ activate_wrn_interceptions: dtcl.InitVar[bool] = True
74
+ exit_on_error: bool = False
75
+
76
+ on_hold: list[lggg.LogRecord] = dtcl.field(init=False, default_factory=list)
77
+ last_message_date: str = dtcl.field(init=False, default="")
78
+ any_handler_shows_memory: bool = dtcl.field(init=False, default=False)
79
+ memory_usages: list[tuple[str, int]] = dtcl.field(init=False, default_factory=list)
80
+ context_levels: list[str] = dtcl.field(init=False, default_factory=list)
81
+ staged_issues: list[issue_t] = dtcl.field(init=False, default_factory=list)
82
+ intercepted_wrn_handle: logger_handle_h | None = dtcl.field(
83
+ init=False, default=None
84
+ )
85
+ intercepted_log_handles: dict[str, logger_handle_h] = dtcl.field(
86
+ init=False, default_factory=dict
87
+ )
88
+
89
+ def __post_init__(
90
+ self, name: str, level: int, activate_wrn_interceptions: bool
91
+ ) -> None:
92
+ """"""
93
+ lggg.Logger.__init__(self, name)
94
+ self.setLevel(level)
95
+ self.propagate = False
96
+
97
+ if activate_wrn_interceptions:
98
+ self._ActivateWarningInterceptions()
99
+
100
+ def _ActivateWarningInterceptions(self) -> None:
101
+ """
102
+ The log message will not appear if called from __post_init__ since there are no
103
+ handlers yet.
104
+ """
105
+ if self.intercepted_wrn_handle is None:
106
+ logger = lggg.getLogger(WARNING_LOGGER_NAME)
107
+
108
+ self.intercepted_wrn_handle = logger.handle
109
+ logger.handle = t.MethodType(_HandleForWarnings(self), logger)
110
+
111
+ lggg.captureWarnings(True)
112
+ self.info("Warning Interception: ON", **HIDE_WHERE_KWARG)
113
+
114
+ def _DeactivateWarningInterceptions(self) -> None:
115
+ """"""
116
+ if self.intercepted_wrn_handle is not None:
117
+ logger = lggg.getLogger(WARNING_LOGGER_NAME)
118
+
119
+ logger.handle = self.intercepted_wrn_handle
120
+ self.intercepted_wrn_handle = None
121
+
122
+ lggg.captureWarnings(False)
123
+ self.info("Warning Interception: OFF", **HIDE_WHERE_KWARG)
124
+
125
+ def ToggleWarningInterceptions(self, state: bool, /) -> None:
126
+ """"""
127
+ if state:
128
+ self._ActivateWarningInterceptions()
129
+ else:
130
+ self._DeactivateWarningInterceptions()
131
+
132
+ def ToggleLogInterceptions(self, state: bool, /) -> None:
133
+ """"""
134
+ if state:
135
+ self.ToggleLogInterceptions(False)
136
+
137
+ all_loggers = [lggg.getLogger()] + [
138
+ lggg.getLogger(_nme)
139
+ for _nme in self.manager.loggerDict
140
+ if _nme not in (self.name, WARNING_LOGGER_NAME)
141
+ ]
142
+ for logger in all_loggers:
143
+ self.intercepted_log_handles[logger.name] = logger.handle
144
+ logger.handle = t.MethodType(
145
+ _HandleForInterceptions(logger, self), logger
146
+ )
147
+
148
+ intercepted = sorted(self.intercepted_log_handles.keys())
149
+ if intercepted.__len__() > 0:
150
+ self.info(
151
+ f"Now Intercepting LOGs from: {str(intercepted)[1:-1]}",
152
+ **HIDE_WHERE_KWARG,
153
+ )
154
+ elif self.intercepted_log_handles.__len__() > 0:
155
+ for name, handle in self.intercepted_log_handles.items():
156
+ logger = lggg.getLogger(name)
157
+ logger.handle = handle
158
+ self.intercepted_log_handles.clear()
159
+ self.info("Log Interception: OFF", **HIDE_WHERE_KWARG)
160
+
161
+ @property
162
+ def max_memory_usage(self) -> int:
163
+ """"""
164
+ return max(tuple(zip(*self.memory_usages))[1])
165
+
166
+ @property
167
+ def max_memory_usage_full(self) -> tuple[str, int]:
168
+ """"""
169
+ where_s, usages = zip(*self.memory_usages)
170
+ max_usage = max(usages)
171
+
172
+ return where_s[usages.index(max_usage)], max_usage
173
+
174
+ def AddHandler(self, handler: lggg.Handler, should_hold_messages: bool, /) -> None:
175
+ """"""
176
+ self.should_hold_messages = should_hold_messages
177
+ lggg.Logger.addHandler(self, handler)
178
+
179
+ extension = getattr(handler, "extension", None)
180
+ if extension is None:
181
+ show_memory_usage = False
182
+ else:
183
+ show_memory_usage = getattr(extension, SHOW_MEMORY_ATTR, False)
184
+ if show_memory_usage:
185
+ self.any_handler_shows_memory = True
186
+
187
+ extension = getattr(handler, "extension", handler.name)
188
+ if isinstance(extension, str):
189
+ name = extension
190
+ else:
191
+ name = getattr(extension, "name", "Anonymous")
192
+ self.info(
193
+ f'New handler "{name}" with class "{type(handler).__name__}" and '
194
+ f"level {lggg.getLevelName(handler.level)}",
195
+ **HIDE_WHERE_KWARG,
196
+ )
197
+
198
+ def handle(self, record: lggg.LogRecord, /) -> None:
199
+ """"""
200
+ if (not self.should_hold_messages) and (self.on_hold.__len__() > 0):
201
+ for hold in self.on_hold:
202
+ lggg.Logger.handle(self, hold)
203
+ self.on_hold.clear()
204
+
205
+ record.elapsed_time = ElapsedTime()
206
+
207
+ if self.any_handler_shows_memory or not self.hasHandlers():
208
+ # Memory usage is also added if there are no handlers yet, just in case.
209
+ usage = CurrentMemoryUsage()
210
+ self.memory_usages.append(
211
+ (f"{record.module}.{record.funcName}.{record.lineno}", usage)
212
+ )
213
+
214
+ value, unit = FormattedMemoryUsage(usage, 1)
215
+ record.memory_usage = f"{value}{unit}"
216
+
217
+ date = dttm.now().strftime(DATE_FORMAT)
218
+ if date != self.last_message_date:
219
+ self.last_message_date = date
220
+ # levelno is added for management by lggg.Logger.handle.
221
+ date_record = lggg.makeLogRecord(
222
+ {
223
+ "levelno": lggg.INFO,
224
+ "msg": f"DATE: {date}",
225
+ SHOW_W_RULE_ATTR: True,
226
+ }
227
+ )
228
+ if self.should_hold_messages:
229
+ self.on_hold.append(date_record)
230
+ else:
231
+ lggg.Logger.handle(self, date_record)
232
+
233
+ if self.should_hold_messages:
234
+ self.on_hold.append(record)
235
+ else:
236
+ lggg.Logger.handle(self, record)
237
+
238
+ if self.exit_on_error and (record.levelno in (lggg.ERROR, lggg.CRITICAL)):
239
+ sstm.exit(1)
240
+
241
+ def AddContextLevel(self, new_level: str, /) -> None:
242
+ """"""
243
+ self.context_levels.append(new_level)
244
+
245
+ def AddedContextLevel(self, new_level: str, /) -> logger_t:
246
+ """
247
+ Meant to be used as:
248
+ with self.AddedContextLevel("new level"):
249
+ ...
250
+ """
251
+ self.AddContextLevel(new_level)
252
+ return self
253
+
254
+ def StageIssue(
255
+ self,
256
+ message: str,
257
+ /,
258
+ *,
259
+ actual: h.Any = NOT_PASSED,
260
+ expected: h.Any | None = None,
261
+ ) -> None:
262
+ """"""
263
+ cls = self.__class__
264
+ context = cls.ISSUE_CONTEXT_SEPARATOR.join(self.context_levels)
265
+ issue = NewIssue(
266
+ context, cls.ISSUE_CONTEXT_END, message, actual=actual, expected=expected
267
+ )
268
+ self.staged_issues.append(issue)
269
+
270
+ @property
271
+ def has_staged_issues(self) -> bool:
272
+ """"""
273
+ return self.staged_issues.__len__() > 0
274
+
275
+ def CommitIssues(
276
+ self,
277
+ level: int,
278
+ /,
279
+ *,
280
+ order: order_h = "when",
281
+ ) -> None:
282
+ """"""
283
+ if not self.has_staged_issues:
284
+ return
285
+
286
+ if order not in ORDER:
287
+ raise ValueError(
288
+ FormattedMessage(
289
+ "Invalid commit order",
290
+ actual=order,
291
+ expected=f"One of {str(ORDER)[1:-1]}",
292
+ )
293
+ )
294
+
295
+ if order == "when":
296
+ issues = self.staged_issues
297
+ else: # order == "context"
298
+ issues = sorted(self.staged_issues, key=lambda _elm: _elm.context)
299
+ issues = "\n".join(issues)
300
+
301
+ self.log(level, issues, **HIDE_WHERE_KWARG)
302
+ self.staged_issues.clear()
303
+
304
+ def __enter__(self) -> None:
305
+ """"""
306
+ pass
307
+
308
+ def __exit__(
309
+ self,
310
+ exc_type: Exception | None,
311
+ exc_value: str | None,
312
+ traceback: traceback_t | None,
313
+ /,
314
+ ) -> bool:
315
+ """"""
316
+ _ = self.context_levels.pop()
317
+ return False
318
+
319
+
320
+ def _HandleForWarnings(interceptor: lggg.Logger, /) -> logger_handle_h:
321
+ """"""
322
+
323
+ def handle_p(_: lggg.Logger, record: lggg.LogRecord, /) -> None:
324
+ pieces = WARNING_TYPE_COMPILED_PATTERN.match(record.msg).group
325
+ module = path_t(pieces(1)).stem
326
+ line = pieces(2)
327
+ kind = pieces(3)
328
+ message = pieces(4)
329
+ duplicate = lggg.makeLogRecord(record.__dict__)
330
+ duplicate.msg = f"{kind}: {message}"
331
+ duplicate.module = module
332
+ duplicate.funcName = "<function>"
333
+ duplicate.lineno = line
334
+ interceptor.handle(duplicate)
335
+
336
+ return handle_p
337
+
338
+
339
+ def _HandleForInterceptions(
340
+ intercepted: lggg.Logger, interceptor: lggg.Logger, /
341
+ ) -> logger_handle_h:
342
+ """"""
343
+
344
+ def handle_p(_: lggg.Logger, record: lggg.LogRecord, /) -> None:
345
+ duplicate = lggg.makeLogRecord(record.__dict__)
346
+ duplicate.msg = f"{intercepted.name}{INTERCEPTED_LOG_SEPARATOR}{record.msg}"
347
+ interceptor.handle(duplicate)
348
+
349
+ return handle_p
logger_36/version.py CHANGED
@@ -29,4 +29,4 @@
29
29
  # The fact that you are presently reading this means that you have had
30
30
  # knowledge of the CeCILL license and that you accept its terms.
31
31
 
32
- __version__ = "2023.13"
32
+ __version__ = "2024.2"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: logger-36
3
- Version: 2023.13
3
+ Version: 2024.2
4
4
  Summary: Simple logger using rich_
5
5
  Home-page: https://src.koda.cnrs.fr/eric.debreuve/logger-36/
6
6
  Author: Eric Debreuve
@@ -16,7 +16,6 @@ Classifier: Programming Language :: Python :: 3.10
16
16
  Classifier: Development Status :: 4 - Beta
17
17
  Requires-Python: >=3.10
18
18
  Description-Content-Type: text/x-rst
19
- Requires-Dist: rich
20
19
 
21
20
  ..
22
21
  Copyright CNRS/Inria/UCA
@@ -0,0 +1,39 @@
1
+ logger_36/__init__.py,sha256=-VGyte6TD6SWU4jBXUjur_xU1R1Asha5KXEwDNmGJ6Q,1756
2
+ logger_36/instance.py,sha256=NQlDAyXV3TNekX9xj9V7JMePmsa2DWnTDaVzh5dcyGM,1616
3
+ logger_36/main.py,sha256=hj3hctMBHJbPWw1078tJ_zOU-6-kEGCzMgHwpWY5ElA,6134
4
+ logger_36/version.py,sha256=k9JK70ov-I4eRm2xjcPqT7aryHlmg6XXYSEUPtNqgU8,1575
5
+ logger_36/catalog/config/console_rich.py,sha256=jJnYXPDsMCTu8zny2X3NdeyKFCfhJupberqIBxyv3LA,2030
6
+ logger_36/catalog/handler/console.py,sha256=PnaCWJsXN-x_-X8i-4o4HWys-7K0A83s4kIdtmDz3AQ,3092
7
+ logger_36/catalog/handler/console_rich.py,sha256=YqKyKwHoYCEVnW1S87NDu3ReTCIzSdYgC-20-813TFQ,5395
8
+ logger_36/catalog/handler/file.py,sha256=BAxA-ZQAikmH0R9Ia3mbSXf-Z60-FfA4ElOVjjmanS0,3507
9
+ logger_36/catalog/handler/generic.py,sha256=1pAmP5vOxBPWhpqoBRDNIc3q14dIDsj7JbX-VqcgUbM,5931
10
+ logger_36/catalog/logging/chronos.py,sha256=5SWyRUhwwKeJg3NPf9jkCqtKc7b_4x58Slbq2iMA8kE,1814
11
+ logger_36/catalog/logging/gpu.py,sha256=OpSQK0paA-xzxeWTKAx9QUqEytFyYvHgiVvWe97-rZ8,2465
12
+ logger_36/catalog/logging/memory.py,sha256=50wX25rXnI8NLlr3gp6793hKUE988CACIXVLMQRUcMs,4038
13
+ logger_36/catalog/logging/system.py,sha256=BzJLBvhyIE5nfUZJo4f1PPmu47YufVyin5ssX9GpXVU,2447
14
+ logger_36/config/issue.py,sha256=cAv4hbikcATtEwMtjgsOcPij8Ylv4XE2dg5hcqaw0FU,1574
15
+ logger_36/config/memory.py,sha256=_cJE_ku9adDk2Pb9jvyQIRilvYRS2uofB8hfTucRrwo,1587
16
+ logger_36/config/message.py,sha256=8AzmioSYDuguK1KN1a84yX0EE-1AnMb7XYgoImtorEA,2056
17
+ logger_36/config/system.py,sha256=d4dddB8IknyGmvOmUdi9Bunc60mEXjwB3AvjyrpCKrY,1847
18
+ logger_36/constant/generic.py,sha256=Tdo8wbhde6hcoB8Xv8AXIkFm4EimOfadDEAacf0j8OE,1614
19
+ logger_36/constant/handler.py,sha256=YoCxN1MTl1c3VuUETjvFKyW_4XM6vwb6BdCUk4Y4_VQ,1681
20
+ logger_36/constant/issue.py,sha256=nq-JDE9pKoshYkXnS-F8R4dlCUCKFQR5w7SwNp-iz30,1656
21
+ logger_36/constant/logger.py,sha256=ze64rQ0oDoC-r0EvX-6qmVN41cG9_vGr7kxrGjtpFvk,2150
22
+ logger_36/constant/memory.py,sha256=9bKK_L4TfNB-Q34qIeTDtDLhQd3p9N0ZHpAmRTXZgJI,1795
23
+ logger_36/constant/message.py,sha256=vT9AukWubfwuQIO10eeR0EMO0Sov9-vLPj95Mg4WPsA,2084
24
+ logger_36/constant/record.py,sha256=79NZCveVyCvwIWOMGmFrdMXsOLdJullguPbY4TB8EZY,1681
25
+ logger_36/constant/system.py,sha256=CLfopBgUhkegE-VQxGRxPMJGanIcK6vkhix8ZzEG5V0,1800
26
+ logger_36/task/inspection.py,sha256=Ozgj_2iQqHEmn6VQPh2rAZJ5233SD1WotFNUOXvukW4,4397
27
+ logger_36/task/storage.py,sha256=y9q8RS_uwxVs89pwecdB7018-4qsgPpAqocAJkhMh-k,5060
28
+ logger_36/task/format/memory.py,sha256=ZeDM6pCMRh81iSifQjiaYHVmKzzR5JhVTqAKd3Dju0U,3610
29
+ logger_36/task/format/message.py,sha256=XAqdR8NWFo-EnzUzaRBFO6jyYb0Su7jCgVQ1HLelxHs,3511
30
+ logger_36/task/format/rule.py,sha256=elNk65Y7HT42otObwfds-DwGwfZae0A77nDPCZuMcGE,1968
31
+ logger_36/task/measure/chronos.py,sha256=qT80jxZm_dAg2P4WkfU0L3PRvRojT21Ps3DtNYqGdrg,2253
32
+ logger_36/task/measure/memory.py,sha256=1f1X-XHd_58LJYJ0Ok5TGIagnf0k5F39IFqWHN2Ojas,1874
33
+ logger_36/type/extension.py,sha256=fsYx0wT1bR6DtpM2VnaxsM0MFv2vBLROgRSCs4duasY,5198
34
+ logger_36/type/issue.py,sha256=4D4e047sHhF3r8YtDj3k50iC5UaSUpXEKMaD9isjspc,2139
35
+ logger_36/type/logger.py,sha256=eIQQiuhicz73ipz-94qGcwxe34sP_HxSgWnFxk78owI,12245
36
+ logger_36-2024.2.dist-info/METADATA,sha256=OFiqvDFojFn_Nog71KVNtDBz_WespEDNYh3u5Ur8ChU,4221
37
+ logger_36-2024.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
38
+ logger_36-2024.2.dist-info/top_level.txt,sha256=sM95BTMWmslEEgR_1pzwZsOeSp8C_QBiu8ImbFr0XLc,10
39
+ logger_36-2024.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: bdist_wheel (0.43.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
logger_36/type/generic.py DELETED
@@ -1,116 +0,0 @@
1
- # Copyright CNRS/Inria/UCA
2
- # Contributor(s): Eric Debreuve (since 2023)
3
- #
4
- # eric.debreuve@cnrs.fr
5
- #
6
- # This software is governed by the CeCILL license under French law and
7
- # abiding by the rules of distribution of free software. You can use,
8
- # modify and/ or redistribute the software under the terms of the CeCILL
9
- # license as circulated by CEA, CNRS and INRIA at the following URL
10
- # "http://www.cecill.info".
11
- #
12
- # As a counterpart to the access to the source code and rights to copy,
13
- # modify and redistribute granted by the license, users are provided only
14
- # with a limited warranty and the software's author, the holder of the
15
- # economic rights, and the successive licensors have only limited
16
- # liability.
17
- #
18
- # In this respect, the user's attention is drawn to the risks associated
19
- # with loading, using, modifying and/or developing or reproducing the
20
- # software by the user in light of its specific status of free software,
21
- # that may mean that it is complicated to manipulate, and that also
22
- # therefore means that it is reserved for developers and experienced
23
- # professionals having in-depth computer knowledge. Users are therefore
24
- # encouraged to load and test the software's suitability as regards their
25
- # requirements in conditions enabling the security of their systems and/or
26
- # data to be ensured and, more generally, to use and operate it in the
27
- # same conditions as regards security.
28
- #
29
- # The fact that you are presently reading this means that you have had
30
- # knowledge of the CeCILL license and that you accept its terms.
31
-
32
- import logging as lggg
33
- from typing import Callable, Protocol
34
-
35
- from rich.console import Console as console_t
36
- from rich.markup import escape as PreProcessedForRich
37
- from rich.terminal_theme import DEFAULT_TERMINAL_THEME
38
-
39
- from logger_36.type.console import console_handler_t
40
- from logger_36.type.extension import handler_extension_t
41
-
42
-
43
- class can_show_message_p(Protocol):
44
- def Show(self, message: str, /) -> None:
45
- ...
46
-
47
-
48
- class generic_handler_t(lggg.Handler, handler_extension_t):
49
- __slots__ = ("console", "Show")
50
- console: console_t | None
51
- Show: Callable[[str], None]
52
-
53
- def __init__(
54
- self,
55
- interface: can_show_message_p | Callable[[str], None],
56
- /,
57
- *args,
58
- supports_html: bool = False,
59
- **kwargs,
60
- ) -> None:
61
- """"""
62
- lggg.Handler.__init__(self, *args, **kwargs)
63
- handler_extension_t.__init__(self)
64
-
65
- if supports_html:
66
- self.console = console_t(
67
- tab_size=console_handler_t.TAB_SIZE,
68
- highlight=False,
69
- force_terminal=True,
70
- )
71
- else:
72
- self.console = None
73
- if hasattr(interface, "Show"):
74
- self.Show = interface.Show
75
- else:
76
- self.Show = interface
77
- self.setFormatter(self.formatter)
78
-
79
- def emit(self, record: lggg.LogRecord, /) -> None:
80
- """"""
81
- if self.console is None:
82
- message, _ = self.MessageLines(record, should_fully_format=True)
83
- else:
84
- first_line, next_lines = self.MessageLines(
85
- record, PreProcessed=PreProcessedForRich
86
- )
87
- highlighted = console_handler_t.HighlightedVersion(
88
- first_line, next_lines, record.levelno
89
- )
90
- segments = self.console.render(highlighted)
91
-
92
- # Inspired from the code of: rich.console.export_html.
93
- html_segments = []
94
- for text, style, _ in segments:
95
- if text == "\n":
96
- html_segments.append("\n")
97
- else:
98
- if style is not None:
99
- style = style.get_html_style(DEFAULT_TERMINAL_THEME)
100
- if (style is not None) and (style.__len__() > 0):
101
- text = f'<span style="{style}">{text}</span>'
102
- html_segments.append(text)
103
- if html_segments[-1] == "\n":
104
- html_segments = html_segments[:-1]
105
-
106
- # /!\ For some reason, the widget splits the message into lines, place each line
107
- # inside a pre tag, and set margin-bottom of the first and list lines to 12px.
108
- # This can be seen by printing self.contents.toHtml(). To avoid the unwanted
109
- # extra margins, margin-bottom is set to 0 below.
110
- message = (
111
- "<pre style='margin-bottom:0px'>" + "".join(html_segments) + "</pre>"
112
- )
113
-
114
- self.Show(message)
115
-
116
- self.ExitOrNotIfError(record)
@@ -1,16 +0,0 @@
1
- logger_36/__init__.py,sha256=UtQbi5wL1lW-C1kJ4ADgX79belpJGnih3SS0291baAc,1782
2
- logger_36/config.py,sha256=uygYJ4rYnBnXKmKXdlQ3RjaRg50Yx2IIq4sCrhzdj8w,2295
3
- logger_36/constant.py,sha256=avAF1WLC_KZQ7d9opLY90L9s9Sr9BhzFIAX2o3QIXY8,2404
4
- logger_36/main.py,sha256=IEVhspokomwGR40w5bO8aP5wzYivYc1BAp2_pwsvKPQ,6302
5
- logger_36/version.py,sha256=odgsu8D49CDnQqs51FIFaHYus8iLmO6XLfpg2L5CTGY,1576
6
- logger_36/measure/chronos.py,sha256=absTi1vArUQYxDKdebgjwijT7xunb5uenIj7pT96Maw,2113
7
- logger_36/measure/memory.py,sha256=N6Y6Qwu1wSQygSMZqREpwdmBFhd280H_ix3k-uGa-Ss,3241
8
- logger_36/task/inspection.py,sha256=pVry624aFjIuiV97AGm_gBvW2QCQvDl-qTnoCKZoVL4,4127
9
- logger_36/type/console.py,sha256=jZfXsn6TQNk2nWXgFIHIi__-5bejqmKkVMLhieIDlLc,4862
10
- logger_36/type/extension.py,sha256=l7ifJGUkji2HLH3g4gojEVLjVZ9djmC6hr3lxV1Rr9s,4812
11
- logger_36/type/file.py,sha256=OLBcnrnQAkIKkVa-qssXMJVdY8kzOmjzQnO9k4NM-sc,2224
12
- logger_36/type/generic.py,sha256=TSK5kQxfhT3NJL4ZQrXB-zO-EWIdK9iztIE_D4GDRWs,4544
13
- logger_36-2023.13.dist-info/METADATA,sha256=Sdrq3a8VZaA2GMU_sNGSPoEmwzar4a08whNy3C5L-c8,4242
14
- logger_36-2023.13.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
15
- logger_36-2023.13.dist-info/top_level.txt,sha256=sM95BTMWmslEEgR_1pzwZsOeSp8C_QBiu8ImbFr0XLc,10
16
- logger_36-2023.13.dist-info/RECORD,,