logger-36 2025.4__py3-none-any.whl → 2025.6__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.
- logger_36/__init__.py +2 -1
- logger_36/api/logger.py +1 -1
- logger_36/api/storage.py +1 -1
- logger_36/catalog/config/console_rich.py +9 -9
- logger_36/{config/logger.py → catalog/config/optional.py} +8 -51
- logger_36/catalog/handler/console.py +15 -8
- logger_36/catalog/handler/console_rich.py +20 -13
- logger_36/catalog/handler/file.py +14 -8
- logger_36/catalog/handler/generic.py +20 -12
- logger_36/catalog/logger/chronos.py +2 -2
- logger_36/catalog/logger/gpu.py +6 -6
- logger_36/catalog/logger/memory.py +3 -3
- logger_36/catalog/logger/system.py +2 -2
- logger_36/constant/error.py +1 -1
- logger_36/constant/handler.py +2 -2
- logger_36/constant/logger.py +2 -9
- logger_36/content.py +3 -3
- logger_36/exception.py +51 -17
- logger_36/gpu.py +1 -1
- logger_36/handler.py +28 -41
- logger_36/instance/logger.py +1 -1
- logger_36/memory.py +9 -6
- logger_36/storage.py +1 -1
- logger_36/system.py +1 -1
- logger_36/task/format/rule.py +4 -2
- logger_36/task/inspection.py +3 -3
- logger_36/task/measure/chronos.py +1 -3
- logger_36/task/measure/memory.py +2 -2
- logger_36/task/storage.py +16 -16
- logger_36/time.py +2 -2
- logger_36/type/handler.py +31 -12
- logger_36/type/issue.py +2 -2
- logger_36/type/logger.py +90 -44
- logger_36/version.py +1 -1
- {logger_36-2025.4.dist-info → logger_36-2025.6.dist-info}/METADATA +1 -1
- logger_36-2025.6.dist-info/RECORD +52 -0
- logger_36-2025.4.dist-info/RECORD +0 -52
- {logger_36-2025.4.dist-info → logger_36-2025.6.dist-info}/WHEEL +0 -0
- {logger_36-2025.4.dist-info → logger_36-2025.6.dist-info}/top_level.txt +0 -0
logger_36/exception.py
CHANGED
@@ -4,23 +4,24 @@ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
|
4
4
|
SEE COPYRIGHT NOTICE BELOW
|
5
5
|
"""
|
6
6
|
|
7
|
-
import
|
7
|
+
import re as r
|
8
|
+
import sys as s
|
8
9
|
import tempfile as tmpf
|
9
10
|
import traceback as tcbk
|
10
11
|
import types as t
|
11
12
|
from pathlib import Path as path_t
|
12
13
|
|
13
|
-
_ORIGINAL_EXCEPTION_HANDLER =
|
14
|
+
_ORIGINAL_EXCEPTION_HANDLER = s.excepthook
|
14
15
|
|
15
16
|
|
16
17
|
def OverrideExceptionFormat() -> None:
|
17
18
|
""""""
|
18
|
-
|
19
|
+
s.excepthook = _HandleException
|
19
20
|
|
20
21
|
|
21
22
|
def ResetExceptionFormat() -> None:
|
22
23
|
""""""
|
23
|
-
|
24
|
+
s.excepthook = _ORIGINAL_EXCEPTION_HANDLER
|
24
25
|
|
25
26
|
|
26
27
|
def _HandleException(
|
@@ -30,25 +31,58 @@ def _HandleException(
|
|
30
31
|
while trace.tb_next is not None:
|
31
32
|
trace = trace.tb_next
|
32
33
|
frame = trace.tb_frame
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
34
|
+
code = frame.f_code
|
35
|
+
module = path_t(code.co_filename)
|
36
|
+
function = code.co_name
|
37
|
+
line_number = frame.f_lineno
|
38
|
+
line_content = module.read_text().splitlines()[line_number - 1].strip()
|
39
|
+
|
40
|
+
# Format module.
|
41
|
+
home = path_t.home()
|
42
|
+
if module.is_relative_to(home):
|
43
|
+
module = path_t("~") / module.relative_to(home)
|
44
|
+
|
45
|
+
# Format line content.
|
46
|
+
if line_content.startswith("raise "):
|
47
|
+
# Do not display code of explicit exception raising.
|
48
|
+
line_content = None
|
49
|
+
|
50
|
+
# Find variables appearing in the line.
|
51
|
+
if line_content is None:
|
52
|
+
line_content = variables = ""
|
53
|
+
else:
|
54
|
+
all_variables = frame.f_locals
|
55
|
+
found_names = []
|
56
|
+
for match in r.finditer(r"[^\d\W]\w*", line_content):
|
57
|
+
name = match.group()
|
58
|
+
if name in all_variables:
|
59
|
+
found_names.append(name)
|
60
|
+
if found_names.__len__() > 0:
|
61
|
+
longest = max(map(len, found_names))
|
62
|
+
variables = map(
|
63
|
+
lambda _: f"{_:{longest}} = {all_variables[_]}", sorted(found_names)
|
64
|
+
)
|
65
|
+
variables = " " + "\n ".join(variables) + "\n"
|
66
|
+
else:
|
67
|
+
variables = ""
|
68
|
+
|
69
|
+
line_content = f" {line_content}\n"
|
70
|
+
|
71
|
+
# Format message.
|
72
|
+
message = str(exception).strip()
|
42
73
|
if message.__len__() > 0:
|
43
|
-
message = f" {message}\n"
|
74
|
+
message = f" {message[0].title()}{message[1:]}\n"
|
44
75
|
|
45
76
|
document = tmpf.NamedTemporaryFile(delete=False)
|
46
77
|
|
47
78
|
print(
|
48
79
|
f"{stripe.__name__}\n"
|
49
|
-
f" {module}
|
50
|
-
f"{
|
51
|
-
|
80
|
+
f" {module}:{function}@{line_number}\n"
|
81
|
+
f"{line_content}"
|
82
|
+
f"{variables}"
|
83
|
+
f"{message}"
|
84
|
+
f" Full report at: {document.name}",
|
85
|
+
file=s.stderr,
|
52
86
|
)
|
53
87
|
|
54
88
|
lines = tcbk.format_exception(exception)
|
logger_36/gpu.py
CHANGED
logger_36/handler.py
CHANGED
@@ -4,38 +4,34 @@ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
|
4
4
|
SEE COPYRIGHT NOTICE BELOW
|
5
5
|
"""
|
6
6
|
|
7
|
-
import logging as
|
8
|
-
import sys as
|
7
|
+
import logging as l
|
8
|
+
import sys as s
|
9
9
|
from pathlib import Path as path_t
|
10
10
|
|
11
|
+
from logger_36.catalog.config.optional import MISSING_RICH_MESSAGE, RICH_IS_AVAILABLE
|
11
12
|
from logger_36.catalog.handler.console import console_handler_t
|
12
13
|
from logger_36.catalog.handler.file import file_handler_t
|
13
14
|
from logger_36.catalog.handler.generic import generic_handler_t, show_message_p
|
14
|
-
from logger_36.constant.error import MISSING_RICH_ERROR
|
15
|
-
from logger_36.instance.logger import LOGGER
|
16
15
|
|
17
|
-
|
16
|
+
if RICH_IS_AVAILABLE:
|
18
17
|
from logger_36.catalog.handler.console_rich import console_rich_handler_t
|
19
|
-
|
20
|
-
_MISSING_RICH_ERROR = None
|
21
|
-
except ModuleNotFoundError:
|
18
|
+
else:
|
22
19
|
from logger_36.catalog.handler.console import (
|
23
20
|
console_handler_t as console_rich_handler_t,
|
24
21
|
)
|
25
|
-
|
26
|
-
_MISSING_RICH_ERROR = MISSING_RICH_ERROR
|
22
|
+
_MISSING_RICH_MESSAGE = MISSING_RICH_MESSAGE
|
27
23
|
|
28
24
|
|
29
25
|
def AddGenericHandler(
|
26
|
+
logger: l.Logger,
|
30
27
|
ShowMessage: show_message_p,
|
31
28
|
/,
|
32
29
|
*,
|
33
|
-
logger: lggg.Logger | None = None,
|
34
30
|
name: str | None = None,
|
35
|
-
level: int =
|
31
|
+
level: int = l.INFO,
|
36
32
|
should_store_memory_usage: bool = False,
|
37
33
|
message_width: int = -1,
|
38
|
-
formatter:
|
34
|
+
formatter: l.Formatter | None = None,
|
39
35
|
supports_html: bool = False,
|
40
36
|
alternating_lines: int = 2,
|
41
37
|
should_record: bool = False,
|
@@ -43,9 +39,6 @@ def AddGenericHandler(
|
|
43
39
|
**kwargs,
|
44
40
|
) -> None:
|
45
41
|
""""""
|
46
|
-
if logger is None:
|
47
|
-
logger = LOGGER
|
48
|
-
|
49
42
|
handler = generic_handler_t(
|
50
43
|
name=name,
|
51
44
|
level=level,
|
@@ -58,23 +51,21 @@ def AddGenericHandler(
|
|
58
51
|
rich_kwargs=kwargs,
|
59
52
|
ShowMessage=ShowMessage,
|
60
53
|
)
|
61
|
-
logger.AddHandler(handler, should_hold_messages)
|
54
|
+
logger.AddHandler(handler, should_hold_messages=should_hold_messages)
|
62
55
|
|
63
56
|
|
64
57
|
def AddConsoleHandler(
|
58
|
+
logger: l.Logger,
|
59
|
+
/,
|
65
60
|
*,
|
66
|
-
logger: lggg.Logger | None = None,
|
67
61
|
name: str | None = None,
|
68
|
-
level: int =
|
62
|
+
level: int = l.INFO,
|
69
63
|
should_store_memory_usage: bool = False,
|
70
64
|
message_width: int = -1,
|
71
|
-
formatter:
|
65
|
+
formatter: l.Formatter | None = None,
|
72
66
|
should_hold_messages: bool = False,
|
73
67
|
) -> None:
|
74
68
|
""""""
|
75
|
-
if logger is None:
|
76
|
-
logger = LOGGER
|
77
|
-
|
78
69
|
handler = console_handler_t(
|
79
70
|
name=name,
|
80
71
|
level=level,
|
@@ -82,17 +73,18 @@ def AddConsoleHandler(
|
|
82
73
|
message_width=message_width,
|
83
74
|
formatter=formatter,
|
84
75
|
)
|
85
|
-
logger.AddHandler(handler, should_hold_messages)
|
76
|
+
logger.AddHandler(handler, should_hold_messages=should_hold_messages)
|
86
77
|
|
87
78
|
|
88
79
|
def AddRichConsoleHandler(
|
80
|
+
logger: l.Logger,
|
81
|
+
/,
|
89
82
|
*,
|
90
|
-
logger: lggg.Logger | None = None,
|
91
83
|
name: str | None = None,
|
92
|
-
level: int =
|
84
|
+
level: int = l.INFO,
|
93
85
|
should_store_memory_usage: bool = False,
|
94
86
|
message_width: int = -1,
|
95
|
-
formatter:
|
87
|
+
formatter: l.Formatter | None = None,
|
96
88
|
alternating_lines: int = 2,
|
97
89
|
should_hold_messages: bool = False,
|
98
90
|
should_install_traceback: bool = False,
|
@@ -100,13 +92,10 @@ def AddRichConsoleHandler(
|
|
100
92
|
**kwargs,
|
101
93
|
) -> None:
|
102
94
|
""""""
|
103
|
-
global
|
104
|
-
if
|
105
|
-
print(
|
106
|
-
|
107
|
-
|
108
|
-
if logger is None:
|
109
|
-
logger = LOGGER
|
95
|
+
global _MISSING_RICH_MESSAGE
|
96
|
+
if _MISSING_RICH_MESSAGE is not None:
|
97
|
+
print(_MISSING_RICH_MESSAGE, file=s.stderr)
|
98
|
+
_MISSING_RICH_MESSAGE = None
|
110
99
|
|
111
100
|
if console_rich_handler_t is console_handler_t:
|
112
101
|
additional_s = {}
|
@@ -125,19 +114,19 @@ def AddRichConsoleHandler(
|
|
125
114
|
formatter=formatter,
|
126
115
|
**additional_s,
|
127
116
|
)
|
128
|
-
logger.AddHandler(handler, should_hold_messages)
|
117
|
+
logger.AddHandler(handler, should_hold_messages=should_hold_messages)
|
129
118
|
|
130
119
|
|
131
120
|
def AddFileHandler(
|
121
|
+
logger: l.Logger,
|
132
122
|
path: str | path_t,
|
133
123
|
/,
|
134
124
|
*args,
|
135
|
-
logger: lggg.Logger | None = None,
|
136
125
|
name: str | None = None,
|
137
|
-
level: int =
|
126
|
+
level: int = l.INFO,
|
138
127
|
should_store_memory_usage: bool = False,
|
139
128
|
message_width: int = -1,
|
140
|
-
formatter:
|
129
|
+
formatter: l.Formatter | None = None,
|
141
130
|
should_hold_messages: bool = False,
|
142
131
|
**kwargs,
|
143
132
|
) -> None:
|
@@ -146,8 +135,6 @@ def AddFileHandler(
|
|
146
135
|
path = path_t(path)
|
147
136
|
if path.exists():
|
148
137
|
raise ValueError(f"File or folder already exists: {path}.")
|
149
|
-
if logger is None:
|
150
|
-
logger = LOGGER
|
151
138
|
|
152
139
|
handler = file_handler_t(
|
153
140
|
name=name,
|
@@ -159,7 +146,7 @@ def AddFileHandler(
|
|
159
146
|
handler_args=args,
|
160
147
|
handler_kwargs=kwargs,
|
161
148
|
)
|
162
|
-
logger.AddHandler(handler, should_hold_messages)
|
149
|
+
logger.AddHandler(handler, should_hold_messages=should_hold_messages)
|
163
150
|
|
164
151
|
|
165
152
|
"""
|
logger_36/instance/logger.py
CHANGED
logger_36/memory.py
CHANGED
@@ -4,14 +4,17 @@ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
|
4
4
|
SEE COPYRIGHT NOTICE BELOW
|
5
5
|
"""
|
6
6
|
|
7
|
-
from logger_36.catalog.logger.memory import
|
8
|
-
|
9
|
-
|
7
|
+
from logger_36.catalog.logger.memory import ( # noqa
|
8
|
+
LogMaximumMemoryUsage,
|
9
|
+
LogMemoryUsages,
|
10
|
+
)
|
11
|
+
from logger_36.task.format.memory import FormattedUsage as FormattedMemoryUsage # noqa
|
12
|
+
from logger_36.task.format.memory import ( # noqa
|
10
13
|
FormattedUsageWithAutoUnit as FormattedMemoryUsageWithAutoUnit,
|
11
14
|
)
|
12
|
-
from logger_36.task.format.memory import UsageBar as MemoryUsageBar
|
13
|
-
from logger_36.task.measure.memory import CanCheckUsage as CanCheckMemoryUsage
|
14
|
-
from logger_36.task.measure.memory import CurrentUsage as CurrentMemoryUsage
|
15
|
+
from logger_36.task.format.memory import UsageBar as MemoryUsageBar # noqa
|
16
|
+
from logger_36.task.measure.memory import CanCheckUsage as CanCheckMemoryUsage # noqa
|
17
|
+
from logger_36.task.measure.memory import CurrentUsage as CurrentMemoryUsage # noqa
|
15
18
|
|
16
19
|
"""
|
17
20
|
COPYRIGHT NOTICE
|
logger_36/storage.py
CHANGED
logger_36/system.py
CHANGED
logger_36/task/format/rule.py
CHANGED
@@ -4,6 +4,8 @@ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
|
4
4
|
SEE COPYRIGHT NOTICE BELOW
|
5
5
|
"""
|
6
6
|
|
7
|
+
from logger_36.catalog.config.optional import RICH_IS_AVAILABLE
|
8
|
+
|
7
9
|
|
8
10
|
def RuleAsText(text: str | None, /) -> str:
|
9
11
|
""""""
|
@@ -13,7 +15,7 @@ def RuleAsText(text: str | None, /) -> str:
|
|
13
15
|
return f"---- ---- ---- ---- {text} ---- ---- ---- ----"
|
14
16
|
|
15
17
|
|
16
|
-
|
18
|
+
if RICH_IS_AVAILABLE:
|
17
19
|
from rich.rule import Rule as rule_t # noqa
|
18
20
|
from rich.text import Text as text_t # noqa
|
19
21
|
|
@@ -24,7 +26,7 @@ try:
|
|
24
26
|
else:
|
25
27
|
return rule_t(title=text_t(text, style=f"bold {color}"), style=color)
|
26
28
|
|
27
|
-
|
29
|
+
else:
|
28
30
|
Rule = lambda _txt, _: RuleAsText(_txt)
|
29
31
|
|
30
32
|
"""
|
logger_36/task/inspection.py
CHANGED
@@ -6,7 +6,7 @@ SEE COPYRIGHT NOTICE BELOW
|
|
6
6
|
|
7
7
|
import importlib.metadata as mprt
|
8
8
|
import pkgutil as pkgs
|
9
|
-
import sys as
|
9
|
+
import sys as s
|
10
10
|
from types import FunctionType, MethodType
|
11
11
|
|
12
12
|
|
@@ -17,8 +17,8 @@ def Modules(
|
|
17
17
|
output = []
|
18
18
|
|
19
19
|
if only_loaded:
|
20
|
-
modules =
|
21
|
-
module_names = set(modules.keys()).difference(
|
20
|
+
modules = s.modules
|
21
|
+
module_names = set(modules.keys()).difference(s.stdlib_module_names)
|
22
22
|
module_names = sorted(module_names, key=str.lower)
|
23
23
|
else:
|
24
24
|
modules = None
|
@@ -22,9 +22,7 @@ def TimeStamp(*, precision: str = "microseconds") -> str:
|
|
22
22
|
)
|
23
23
|
|
24
24
|
|
25
|
-
def ElapsedTime(
|
26
|
-
*, should_return_now: bool = False
|
27
|
-
) -> str | tuple[str, date_time_t]:
|
25
|
+
def ElapsedTime(*, should_return_now: bool = False) -> str | tuple[str, date_time_t]:
|
28
26
|
""""""
|
29
27
|
now = date_time_t.now()
|
30
28
|
elapsed_seconds = (now - _START_DATE_AND_TIME).total_seconds()
|
logger_36/task/measure/memory.py
CHANGED
logger_36/task/storage.py
CHANGED
@@ -5,18 +5,20 @@ SEE COPYRIGHT NOTICE BELOW
|
|
5
5
|
"""
|
6
6
|
|
7
7
|
import dataclasses as d
|
8
|
-
import logging as
|
9
|
-
import re as
|
8
|
+
import logging as l
|
9
|
+
import re as r
|
10
10
|
from html.parser import HTMLParser as html_parser_t
|
11
11
|
from io import IOBase as io_base_t
|
12
12
|
from pathlib import Path as path_t
|
13
13
|
|
14
|
-
|
14
|
+
from logger_36.catalog.config.optional import RICH_IS_AVAILABLE
|
15
|
+
from logger_36.instance.logger import L
|
16
|
+
|
17
|
+
if RICH_IS_AVAILABLE:
|
15
18
|
from rich.console import Console as console_t # noqa
|
16
|
-
|
19
|
+
else:
|
17
20
|
console_t = None
|
18
21
|
|
19
|
-
from logger_36.instance.logger import LOGGER
|
20
22
|
|
21
23
|
_BODY_END_PATTERN = r"</[bB][oO][dD][yY]>(.|\n)*$"
|
22
24
|
|
@@ -60,7 +62,7 @@ class html_reader_t(html_parser_t):
|
|
60
62
|
output[self.body_position_start[0] : (self.body_position_end[0] + 1)]
|
61
63
|
)
|
62
64
|
output = output[self.body_position_start[1] :]
|
63
|
-
output =
|
65
|
+
output = r.sub(_BODY_END_PATTERN, "", output, count=1)
|
64
66
|
|
65
67
|
return output.strip()
|
66
68
|
|
@@ -77,19 +79,19 @@ def SaveLOGasHTML(path: str | path_t | io_base_t | None = None) -> None:
|
|
77
79
|
cannot_save = "Cannot save logging record as HTML"
|
78
80
|
|
79
81
|
if console_t is None:
|
80
|
-
|
82
|
+
L.warning(f"{cannot_save}: The Rich console cannot be imported.")
|
81
83
|
return
|
82
84
|
|
83
85
|
if path is None:
|
84
|
-
for handler in
|
85
|
-
if isinstance(handler,
|
86
|
+
for handler in L.handlers:
|
87
|
+
if isinstance(handler, l.FileHandler):
|
86
88
|
path = path_t(handler.baseFilename).with_suffix(".htm")
|
87
89
|
break
|
88
90
|
if path is None:
|
89
|
-
|
91
|
+
L.warning(f"{cannot_save}: No file handler to build a filename from.")
|
90
92
|
return
|
91
93
|
if path.exists():
|
92
|
-
|
94
|
+
L.warning(
|
93
95
|
f'{cannot_save}: Automatically generated path "{path}" already exists.'
|
94
96
|
)
|
95
97
|
return
|
@@ -98,10 +100,10 @@ def SaveLOGasHTML(path: str | path_t | io_base_t | None = None) -> None:
|
|
98
100
|
|
99
101
|
actual_file = isinstance(path, path_t)
|
100
102
|
if actual_file and path.exists():
|
101
|
-
|
103
|
+
L.warning(f'{cannot_save}: File "{path}" already exists.')
|
102
104
|
return
|
103
105
|
|
104
|
-
for handler in
|
106
|
+
for handler in L.handlers:
|
105
107
|
console = getattr(handler, "console", None)
|
106
108
|
if isinstance(console, console_t) and console.record:
|
107
109
|
html = console.export_html()
|
@@ -112,9 +114,7 @@ def SaveLOGasHTML(path: str | path_t | io_base_t | None = None) -> None:
|
|
112
114
|
path.write(html)
|
113
115
|
break
|
114
116
|
else:
|
115
|
-
|
116
|
-
f"{cannot_save}: No handler has a RICH console with recording ON."
|
117
|
-
)
|
117
|
+
L.warning(f"{cannot_save}: No handler has a RICH console with recording ON.")
|
118
118
|
|
119
119
|
|
120
120
|
"""
|
logger_36/time.py
CHANGED
@@ -4,8 +4,8 @@ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
|
4
4
|
SEE COPYRIGHT NOTICE BELOW
|
5
5
|
"""
|
6
6
|
|
7
|
-
from logger_36.catalog.logger.chronos import LogElapsedTime
|
8
|
-
from logger_36.task.measure.chronos import ElapsedTime, TimeStamp
|
7
|
+
from logger_36.catalog.logger.chronos import LogElapsedTime # noqa
|
8
|
+
from logger_36.task.measure.chronos import ElapsedTime, TimeStamp # noqa
|
9
9
|
|
10
10
|
"""
|
11
11
|
COPYRIGHT NOTICE
|
logger_36/type/handler.py
CHANGED
@@ -5,8 +5,8 @@ SEE COPYRIGHT NOTICE BELOW
|
|
5
5
|
"""
|
6
6
|
|
7
7
|
import dataclasses as d
|
8
|
-
import logging as
|
9
|
-
import sys as
|
8
|
+
import logging as l
|
9
|
+
import sys as s
|
10
10
|
import typing as h
|
11
11
|
|
12
12
|
from logger_36.config.message import (
|
@@ -16,12 +16,31 @@ from logger_36.config.message import (
|
|
16
16
|
WHERE_SEPARATOR,
|
17
17
|
)
|
18
18
|
from logger_36.constant.error import MEMORY_MEASURE_ERROR
|
19
|
-
from logger_36.constant.handler import
|
19
|
+
from logger_36.constant.handler import HANDLER_KINDS
|
20
20
|
from logger_36.constant.message import NEXT_LINE_PROLOGUE
|
21
21
|
from logger_36.task.format.message import MessageWithActualExpected
|
22
22
|
from logger_36.task.measure.chronos import TimeStamp
|
23
23
|
from logger_36.task.measure.memory import CanCheckUsage as CanCheckMemoryUsage
|
24
24
|
|
25
|
+
|
26
|
+
@h.runtime_checkable
|
27
|
+
class message_from_record_raw_p(h.Protocol):
|
28
|
+
def __call__(self, record: l.LogRecord, /) -> str: ...
|
29
|
+
|
30
|
+
|
31
|
+
@h.runtime_checkable
|
32
|
+
class message_from_record_preprocessed_p(h.Protocol):
|
33
|
+
def __call__(
|
34
|
+
self,
|
35
|
+
record: l.LogRecord,
|
36
|
+
/,
|
37
|
+
*,
|
38
|
+
PreProcessed: h.Callable[[str], str] | None = None,
|
39
|
+
) -> str: ...
|
40
|
+
|
41
|
+
|
42
|
+
message_from_record_h = message_from_record_raw_p | message_from_record_preprocessed_p
|
43
|
+
|
25
44
|
_MEMORY_MEASURE_ERROR = MEMORY_MEASURE_ERROR
|
26
45
|
|
27
46
|
|
@@ -30,24 +49,24 @@ class handler_extension_t:
|
|
30
49
|
name: str | None = None
|
31
50
|
should_store_memory_usage: bool = False
|
32
51
|
message_width: int = -1
|
33
|
-
MessageFromRecord:
|
52
|
+
MessageFromRecord: message_from_record_h = d.field(init=False)
|
34
53
|
|
35
|
-
handler: d.InitVar[
|
36
|
-
level: d.InitVar[int] =
|
37
|
-
formatter: d.InitVar[
|
54
|
+
handler: d.InitVar[l.Handler | None] = None
|
55
|
+
level: d.InitVar[int] = l.NOTSET
|
56
|
+
formatter: d.InitVar[l.Formatter | None] = None
|
38
57
|
|
39
58
|
def __post_init__(
|
40
|
-
self, handler:
|
59
|
+
self, handler: l.Handler | None, level: int, formatter: l.Formatter | None
|
41
60
|
) -> None:
|
42
61
|
""""""
|
43
62
|
global _MEMORY_MEASURE_ERROR
|
44
63
|
|
45
|
-
if self.name in
|
64
|
+
if self.name in HANDLER_KINDS:
|
46
65
|
raise ValueError(
|
47
66
|
MessageWithActualExpected(
|
48
67
|
"Invalid handler name",
|
49
68
|
actual=self.name,
|
50
|
-
expected=f"a name not in {str(
|
69
|
+
expected=f"a name not in {str(HANDLER_KINDS)[1:-1]}",
|
51
70
|
)
|
52
71
|
)
|
53
72
|
|
@@ -57,7 +76,7 @@ class handler_extension_t:
|
|
57
76
|
if self.should_store_memory_usage and not CanCheckMemoryUsage():
|
58
77
|
self.should_store_memory_usage = False
|
59
78
|
if _MEMORY_MEASURE_ERROR is not None:
|
60
|
-
print(_MEMORY_MEASURE_ERROR, file=
|
79
|
+
print(_MEMORY_MEASURE_ERROR, file=s.stderr)
|
61
80
|
_MEMORY_MEASURE_ERROR = None
|
62
81
|
|
63
82
|
handler.setLevel(level)
|
@@ -72,7 +91,7 @@ class handler_extension_t:
|
|
72
91
|
|
73
92
|
def _MessageFromRecord(
|
74
93
|
self,
|
75
|
-
record:
|
94
|
+
record: l.LogRecord,
|
76
95
|
/,
|
77
96
|
*,
|
78
97
|
PreProcessed: h.Callable[[str], str] | None = None,
|
logger_36/type/issue.py
CHANGED
@@ -4,7 +4,7 @@ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
|
4
4
|
SEE COPYRIGHT NOTICE BELOW
|
5
5
|
"""
|
6
6
|
|
7
|
-
import logging as
|
7
|
+
import logging as l
|
8
8
|
import typing as h
|
9
9
|
|
10
10
|
from logger_36.config.issue import ISSUE_BASE_CONTEXT
|
@@ -22,7 +22,7 @@ def NewIssue(
|
|
22
22
|
message: str,
|
23
23
|
/,
|
24
24
|
*,
|
25
|
-
level: int =
|
25
|
+
level: int = l.ERROR,
|
26
26
|
actual: h.Any = NOT_PASSED,
|
27
27
|
expected: h.Any | None = None,
|
28
28
|
expected_is_choices: bool = False,
|