logger-36 2024.27__py3-none-any.whl → 2024.29__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/catalog/config/console_rich.py +9 -9
- logger_36/catalog/handler/console.py +12 -11
- logger_36/catalog/handler/console_rich.py +24 -42
- logger_36/catalog/handler/file.py +12 -11
- logger_36/catalog/handler/generic.py +33 -15
- logger_36/catalog/logger/chronos.py +1 -2
- logger_36/catalog/logger/gpu.py +0 -2
- logger_36/catalog/logger/memory.py +6 -9
- logger_36/catalog/logger/system.py +0 -2
- logger_36/config/logger.py +2 -2
- logger_36/config/message.py +5 -6
- logger_36/constant/logger.py +0 -4
- logger_36/constant/message.py +3 -1
- logger_36/constant/record.py +3 -4
- logger_36/content.py +1 -1
- logger_36/handler.py +10 -19
- logger_36/task/format/memory.py +2 -2
- logger_36/task/format/message.py +1 -25
- logger_36/task/measure/chronos.py +19 -9
- logger_36/type/handler.py +34 -73
- logger_36/type/issue.py +2 -2
- logger_36/type/logger.py +99 -57
- logger_36/version.py +1 -1
- {logger_36-2024.27.dist-info → logger_36-2024.29.dist-info}/METADATA +1 -1
- logger_36-2024.29.dist-info/RECORD +52 -0
- {logger_36-2024.27.dist-info → logger_36-2024.29.dist-info}/WHEEL +1 -1
- logger_36-2024.27.dist-info/RECORD +0 -52
- {logger_36-2024.27.dist-info → logger_36-2024.29.dist-info}/top_level.txt +0 -0
@@ -12,23 +12,23 @@ from rich.style import Style as style_t
|
|
12
12
|
"""
|
13
13
|
Colors: See https://rich.readthedocs.io/en/stable/appendix/colors.html.
|
14
14
|
"""
|
15
|
-
|
15
|
+
WHITE_COLOR = "grey85"
|
16
|
+
GRAY_COLOR = "grey58"
|
17
|
+
|
16
18
|
LEVEL_COLOR: dict[int, str | style_t] = {
|
17
19
|
lggg.DEBUG: "orchid",
|
18
|
-
lggg.INFO:
|
20
|
+
lggg.INFO: GRAY_COLOR,
|
19
21
|
lggg.WARNING: "yellow1",
|
20
|
-
lggg.ERROR: "
|
21
|
-
lggg.CRITICAL: "
|
22
|
+
lggg.ERROR: "dark_orange",
|
23
|
+
lggg.CRITICAL: "bright_red",
|
22
24
|
}
|
23
|
-
ACTUAL_COLOR =
|
24
|
-
EXPECTED_COLOR = "
|
25
|
-
|
25
|
+
ACTUAL_COLOR = LEVEL_COLOR[lggg.CRITICAL]
|
26
|
+
EXPECTED_COLOR = "green3"
|
27
|
+
DATE_TIME_COLOR = "sky_blue3"
|
26
28
|
|
27
29
|
ALTERNATIVE_BACKGROUND_FOR_LIGHT = style_t(bgcolor=color_t.from_rgb(230, 230, 230))
|
28
30
|
ALTERNATIVE_BACKGROUND_FOR_DARK = style_t(bgcolor=color_t.from_rgb(25, 25, 25))
|
29
31
|
|
30
|
-
GRAY_STYLE = style_t(color=color_t.from_rgb(150, 150, 150))
|
31
|
-
|
32
32
|
"""
|
33
33
|
COPYRIGHT NOTICE
|
34
34
|
|
@@ -6,7 +6,7 @@ SEE COPYRIGHT NOTICE BELOW
|
|
6
6
|
|
7
7
|
import dataclasses as d
|
8
8
|
import logging as lggg
|
9
|
-
import textwrap as
|
9
|
+
import textwrap as txt_
|
10
10
|
import typing as h
|
11
11
|
|
12
12
|
from logger_36.constant.message import LINE_INDENT
|
@@ -18,12 +18,11 @@ from logger_36.type.handler import handler_extension_t
|
|
18
18
|
@d.dataclass(slots=True, repr=False, eq=False)
|
19
19
|
class console_handler_t(lggg.Handler):
|
20
20
|
extension: handler_extension_t = d.field(init=False)
|
21
|
-
|
21
|
+
MessageFromRecord: h.Callable[..., tuple[str, str | None]] = d.field(init=False)
|
22
22
|
|
23
23
|
name: d.InitVar[str | None] = None
|
24
24
|
level: d.InitVar[int] = lggg.NOTSET
|
25
|
-
|
26
|
-
show_memory_usage: d.InitVar[bool] = False
|
25
|
+
should_store_memory_usage: d.InitVar[bool] = False
|
27
26
|
message_width: d.InitVar[int] = -1
|
28
27
|
formatter: d.InitVar[lggg.Formatter | None] = None
|
29
28
|
|
@@ -31,8 +30,7 @@ class console_handler_t(lggg.Handler):
|
|
31
30
|
self,
|
32
31
|
name: str | None,
|
33
32
|
level: int,
|
34
|
-
|
35
|
-
show_memory_usage: bool,
|
33
|
+
should_store_memory_usage: bool,
|
36
34
|
message_width: int,
|
37
35
|
formatter: lggg.Formatter | None,
|
38
36
|
) -> None:
|
@@ -41,22 +39,21 @@ class console_handler_t(lggg.Handler):
|
|
41
39
|
|
42
40
|
self.extension = handler_extension_t(
|
43
41
|
name=name,
|
44
|
-
|
45
|
-
show_memory_usage=show_memory_usage,
|
42
|
+
should_store_memory_usage=should_store_memory_usage,
|
46
43
|
handler=self,
|
47
44
|
level=level,
|
48
45
|
message_width=message_width,
|
49
46
|
formatter=formatter,
|
50
47
|
)
|
51
48
|
|
52
|
-
self.
|
49
|
+
self.MessageFromRecord = self.extension.MessageFromRecord
|
53
50
|
|
54
51
|
def emit(self, record: lggg.LogRecord, /) -> None:
|
55
52
|
""""""
|
56
53
|
if hasattr(record, SHOW_W_RULE_ATTR):
|
57
54
|
message = RuleAsText(record.msg)
|
58
55
|
else:
|
59
|
-
message
|
56
|
+
message = self.MessageFromRecord(record)
|
60
57
|
print(message)
|
61
58
|
|
62
59
|
def ShowMessage(self, message: str, /, *, indented: bool = False) -> None:
|
@@ -65,9 +62,13 @@ class console_handler_t(lggg.Handler):
|
|
65
62
|
logger_36.catalog.handler.generic.generic_handler_t.ShowMessage.
|
66
63
|
"""
|
67
64
|
if indented:
|
68
|
-
message =
|
65
|
+
message = txt_.indent(message, LINE_INDENT)
|
69
66
|
print(message)
|
70
67
|
|
68
|
+
def DisplayRule(self, /, *, text: str | None = None, color: str = "white") -> None:
|
69
|
+
""""""
|
70
|
+
self.ShowMessage(RuleAsText(text))
|
71
|
+
|
71
72
|
|
72
73
|
"""
|
73
74
|
COPYRIGHT NOTICE
|
@@ -6,7 +6,7 @@ SEE COPYRIGHT NOTICE BELOW
|
|
6
6
|
|
7
7
|
import dataclasses as d
|
8
8
|
import logging as lggg
|
9
|
-
import textwrap as
|
9
|
+
import textwrap as txt_
|
10
10
|
import typing as h
|
11
11
|
|
12
12
|
from logger_36.catalog.config.console_rich import (
|
@@ -14,19 +14,13 @@ from logger_36.catalog.config.console_rich import (
|
|
14
14
|
ALTERNATIVE_BACKGROUND_FOR_DARK,
|
15
15
|
ALTERNATIVE_BACKGROUND_FOR_LIGHT,
|
16
16
|
DATE_TIME_COLOR,
|
17
|
-
ELAPSED_TIME_COLOR,
|
18
17
|
EXPECTED_COLOR,
|
19
|
-
|
18
|
+
GRAY_COLOR,
|
20
19
|
LEVEL_COLOR,
|
20
|
+
WHITE_COLOR,
|
21
21
|
)
|
22
|
-
from logger_36.config.message import
|
23
|
-
|
24
|
-
ELAPSED_TIME_SEPARATOR,
|
25
|
-
EXPECTED_PATTERNS,
|
26
|
-
LEVEL_CLOSING,
|
27
|
-
WHERE_SEPARATOR,
|
28
|
-
)
|
29
|
-
from logger_36.constant.message import LINE_INDENT
|
22
|
+
from logger_36.config.message import ACTUAL_PATTERNS, EXPECTED_PATTERNS, WHERE_SEPARATOR
|
23
|
+
from logger_36.constant.message import CONTEXT_LENGTH, LINE_INDENT
|
30
24
|
from logger_36.constant.record import SHOW_W_RULE_ATTR
|
31
25
|
from logger_36.task.format.rule import Rule
|
32
26
|
from logger_36.type.handler import handler_extension_t
|
@@ -63,14 +57,13 @@ class console_rich_handler_t(lggg.Handler):
|
|
63
57
|
|
64
58
|
extension: handler_extension_t = d.field(init=False)
|
65
59
|
console: console_t = d.field(init=False)
|
66
|
-
|
60
|
+
MessageFromRecord: h.Callable[..., str] = d.field(init=False)
|
67
61
|
alternating_lines: int = 0
|
68
62
|
background_is_light: bool = True
|
69
63
|
|
70
64
|
name: d.InitVar[str | None] = None
|
71
65
|
level: d.InitVar[int] = lggg.NOTSET
|
72
|
-
|
73
|
-
show_memory_usage: d.InitVar[bool] = False
|
66
|
+
should_store_memory_usage: d.InitVar[bool] = False
|
74
67
|
message_width: d.InitVar[int] = -1
|
75
68
|
formatter: d.InitVar[lggg.Formatter | None] = None
|
76
69
|
should_install_traceback: d.InitVar[bool] = False
|
@@ -82,8 +75,7 @@ class console_rich_handler_t(lggg.Handler):
|
|
82
75
|
self,
|
83
76
|
name: str | None,
|
84
77
|
level: int,
|
85
|
-
|
86
|
-
show_memory_usage: bool,
|
78
|
+
should_store_memory_usage: bool,
|
87
79
|
message_width: int,
|
88
80
|
formatter: lggg.Formatter | None,
|
89
81
|
should_install_traceback: bool,
|
@@ -95,8 +87,7 @@ class console_rich_handler_t(lggg.Handler):
|
|
95
87
|
|
96
88
|
self.extension = handler_extension_t(
|
97
89
|
name=name,
|
98
|
-
|
99
|
-
show_memory_usage=show_memory_usage,
|
90
|
+
should_store_memory_usage=should_store_memory_usage,
|
100
91
|
handler=self,
|
101
92
|
level=level,
|
102
93
|
message_width=message_width,
|
@@ -126,7 +117,7 @@ class console_rich_handler_t(lggg.Handler):
|
|
126
117
|
rich_traceback_kwargs["console"] = self.console
|
127
118
|
InstallTracebackHandler(**rich_traceback_kwargs)
|
128
119
|
|
129
|
-
self.
|
120
|
+
self.MessageFromRecord = self.extension.MessageFromRecord
|
130
121
|
if self.alternating_lines == 1:
|
131
122
|
self.alternating_lines = 0
|
132
123
|
self.background_is_light = False
|
@@ -141,14 +132,13 @@ class console_rich_handler_t(lggg.Handler):
|
|
141
132
|
if hasattr(record, SHOW_W_RULE_ATTR):
|
142
133
|
richer = Rule(record.msg, DATE_TIME_COLOR)
|
143
134
|
else:
|
144
|
-
|
135
|
+
message = self.MessageFromRecord(record, PreProcessed=EscapedVersion)
|
145
136
|
should_highlight_back = self.alternating_lines == 1
|
146
137
|
if self.alternating_lines >= 0:
|
147
138
|
self.alternating_lines = (self.alternating_lines + 1) % 2
|
148
139
|
richer = HighlightedVersion(
|
149
140
|
self.console,
|
150
|
-
|
151
|
-
next_s,
|
141
|
+
message,
|
152
142
|
record.levelno,
|
153
143
|
should_highlight_back=should_highlight_back,
|
154
144
|
background_is_light=self.background_is_light,
|
@@ -161,14 +151,17 @@ class console_rich_handler_t(lggg.Handler):
|
|
161
151
|
logger_36.catalog.handler.generic.generic_handler_t.ShowMessage.
|
162
152
|
"""
|
163
153
|
if indented:
|
164
|
-
message =
|
154
|
+
message = txt_.indent(message, LINE_INDENT)
|
165
155
|
self.console.print(message, crop=False, overflow="ignore")
|
166
156
|
|
157
|
+
def DisplayRule(self, /, *, text: str | None = None, color: str = "white") -> None:
|
158
|
+
""""""
|
159
|
+
self.ShowMessage(Rule(text, color))
|
160
|
+
|
167
161
|
|
168
162
|
def HighlightedVersion(
|
169
163
|
_: console_t,
|
170
|
-
|
171
|
-
next_lines: str | None,
|
164
|
+
message: str,
|
172
165
|
log_level: int,
|
173
166
|
/,
|
174
167
|
*,
|
@@ -176,24 +169,13 @@ def HighlightedVersion(
|
|
176
169
|
background_is_light: bool = True,
|
177
170
|
) -> renderable_t:
|
178
171
|
""""""
|
179
|
-
output = text_t(
|
180
|
-
|
181
|
-
# Used instead of _CONTEXT_LENGTH which might include \t, thus creating a
|
182
|
-
# mismatch between character length and length when displayed in console.
|
183
|
-
context_end = first_line.find(LEVEL_CLOSING)
|
184
|
-
elapsed_time_separator = first_line.rfind(ELAPSED_TIME_SEPARATOR)
|
185
|
-
where_separator = first_line.rfind(
|
186
|
-
WHERE_SEPARATOR, context_end, elapsed_time_separator
|
187
|
-
)
|
188
|
-
|
189
|
-
output.stylize(LEVEL_COLOR[log_level], end=context_end + 1)
|
190
|
-
output.stylize(GRAY_STYLE, start=where_separator, end=elapsed_time_separator)
|
191
|
-
output.stylize(ELAPSED_TIME_COLOR, start=elapsed_time_separator)
|
192
|
-
|
193
|
-
if next_lines is not None:
|
194
|
-
output.append(next_lines)
|
172
|
+
output = text_t(message, WHITE_COLOR)
|
195
173
|
|
196
|
-
|
174
|
+
output.stylize(LEVEL_COLOR[log_level], end=CONTEXT_LENGTH)
|
175
|
+
where = message.rfind(WHERE_SEPARATOR)
|
176
|
+
if (where >= 0) and ("\n" not in message[where:]):
|
177
|
+
output.stylize(GRAY_COLOR, start=where)
|
178
|
+
_ = output.highlight_words(ACTUAL_PATTERNS, style=ACTUAL_COLOR)
|
197
179
|
_ = output.highlight_regex(EXPECTED_PATTERNS, style=EXPECTED_COLOR)
|
198
180
|
|
199
181
|
if should_highlight_back:
|
@@ -6,7 +6,7 @@ SEE COPYRIGHT NOTICE BELOW
|
|
6
6
|
|
7
7
|
import dataclasses as d
|
8
8
|
import logging as lggg
|
9
|
-
import textwrap as
|
9
|
+
import textwrap as txt_
|
10
10
|
import typing as h
|
11
11
|
from pathlib import Path as path_t
|
12
12
|
|
@@ -20,12 +20,11 @@ from logger_36.type.handler import handler_extension_t
|
|
20
20
|
class file_handler_t(lggg.FileHandler):
|
21
21
|
|
22
22
|
extension: handler_extension_t = d.field(init=False)
|
23
|
-
|
23
|
+
MessageFromRecord: h.Callable[..., tuple[str, str | None]] = d.field(init=False)
|
24
24
|
|
25
25
|
name: d.InitVar[str | None] = None
|
26
26
|
level: d.InitVar[int] = lggg.NOTSET
|
27
|
-
|
28
|
-
show_memory_usage: d.InitVar[bool] = False
|
27
|
+
should_store_memory_usage: d.InitVar[bool] = False
|
29
28
|
message_width: d.InitVar[int] = -1
|
30
29
|
formatter: d.InitVar[lggg.Formatter | None] = None
|
31
30
|
|
@@ -37,8 +36,7 @@ class file_handler_t(lggg.FileHandler):
|
|
37
36
|
self,
|
38
37
|
name: str | None,
|
39
38
|
level: int,
|
40
|
-
|
41
|
-
show_memory_usage: bool,
|
39
|
+
should_store_memory_usage: bool,
|
42
40
|
message_width: int,
|
43
41
|
formatter: lggg.Formatter | None,
|
44
42
|
path: path_t | None,
|
@@ -50,22 +48,21 @@ class file_handler_t(lggg.FileHandler):
|
|
50
48
|
|
51
49
|
self.extension = handler_extension_t(
|
52
50
|
name=name,
|
53
|
-
|
54
|
-
show_memory_usage=show_memory_usage,
|
51
|
+
should_store_memory_usage=should_store_memory_usage,
|
55
52
|
handler=self,
|
56
53
|
level=level,
|
57
54
|
message_width=message_width,
|
58
55
|
formatter=formatter,
|
59
56
|
)
|
60
57
|
|
61
|
-
self.
|
58
|
+
self.MessageFromRecord = self.extension.MessageFromRecord
|
62
59
|
|
63
60
|
def emit(self, record: lggg.LogRecord, /) -> None:
|
64
61
|
""""""
|
65
62
|
if hasattr(record, SHOW_W_RULE_ATTR):
|
66
63
|
message = RuleAsText(record.msg)
|
67
64
|
else:
|
68
|
-
message
|
65
|
+
message = self.MessageFromRecord(record)
|
69
66
|
print(message, file=self.stream)
|
70
67
|
self.stream.flush()
|
71
68
|
|
@@ -75,10 +72,14 @@ class file_handler_t(lggg.FileHandler):
|
|
75
72
|
logger_36.catalog.handler.generic.generic_handler_t.ShowMessage.
|
76
73
|
"""
|
77
74
|
if indented:
|
78
|
-
message =
|
75
|
+
message = txt_.indent(message, LINE_INDENT)
|
79
76
|
print(message, file=self.stream)
|
80
77
|
self.stream.flush()
|
81
78
|
|
79
|
+
def DisplayRule(self, /, *, text: str | None = None, color: str = "white") -> None:
|
80
|
+
""""""
|
81
|
+
self.ShowMessage(RuleAsText(text))
|
82
|
+
|
82
83
|
|
83
84
|
"""
|
84
85
|
COPYRIGHT NOTICE
|
@@ -23,6 +23,14 @@ from logger_36.task.format.rule import Rule, RuleAsText
|
|
23
23
|
from logger_36.type.handler import handler_extension_t
|
24
24
|
|
25
25
|
|
26
|
+
class show_message_p(h.Protocol):
|
27
|
+
def __call__(self, message: str, /, *, indented: bool = False) -> None: ...
|
28
|
+
|
29
|
+
|
30
|
+
class display_rule_p(h.Protocol):
|
31
|
+
def __call__(self, /, *, text: str | None = None, color: str = "white") -> None: ...
|
32
|
+
|
33
|
+
|
26
34
|
@d.dataclass(slots=True, repr=False, eq=False)
|
27
35
|
class generic_handler_t(lggg.Handler):
|
28
36
|
"""
|
@@ -44,19 +52,19 @@ class generic_handler_t(lggg.Handler):
|
|
44
52
|
it is indeed called at the end of the emit method.
|
45
53
|
"""
|
46
54
|
|
47
|
-
ShowMessage:
|
48
|
-
console: console_t = None
|
49
|
-
console_options: console_options_t = None
|
55
|
+
ShowMessage: show_message_p
|
56
|
+
console: console_t | None = None
|
57
|
+
console_options: console_options_t | None = None
|
50
58
|
alternating_lines: int = 0
|
51
59
|
background_is_light: bool = True
|
52
60
|
|
61
|
+
DisplayRule: display_rule_p = d.field(init=False)
|
53
62
|
extension: handler_extension_t = d.field(init=False)
|
54
|
-
|
63
|
+
MessageFromRecord: h.Callable[..., tuple[str, str | None]] = d.field(init=False)
|
55
64
|
|
56
65
|
name: d.InitVar[str | None] = None
|
57
66
|
level: d.InitVar[int] = lggg.NOTSET
|
58
|
-
|
59
|
-
show_memory_usage: d.InitVar[bool] = False
|
67
|
+
should_store_memory_usage: d.InitVar[bool] = False
|
60
68
|
message_width: d.InitVar[int] = -1
|
61
69
|
formatter: d.InitVar[lggg.Formatter | None] = None
|
62
70
|
|
@@ -68,8 +76,7 @@ class generic_handler_t(lggg.Handler):
|
|
68
76
|
self,
|
69
77
|
name: str | None,
|
70
78
|
level: int,
|
71
|
-
|
72
|
-
show_memory_usage: bool,
|
79
|
+
should_store_memory_usage: bool,
|
73
80
|
message_width: int,
|
74
81
|
formatter: lggg.Formatter | None,
|
75
82
|
supports_html: bool,
|
@@ -81,8 +88,7 @@ class generic_handler_t(lggg.Handler):
|
|
81
88
|
|
82
89
|
self.extension = handler_extension_t(
|
83
90
|
name=name,
|
84
|
-
|
85
|
-
show_memory_usage=show_memory_usage,
|
91
|
+
should_store_memory_usage=should_store_memory_usage,
|
86
92
|
handler=self,
|
87
93
|
level=level,
|
88
94
|
message_width=message_width,
|
@@ -101,8 +107,11 @@ class generic_handler_t(lggg.Handler):
|
|
101
107
|
self.console_options = self.console.options.update(
|
102
108
|
overflow="ignore", no_wrap=True
|
103
109
|
)
|
110
|
+
self.DisplayRule = self._DisplayRule
|
111
|
+
else:
|
112
|
+
self.DisplayRule = self._DisplayRuleAsText
|
104
113
|
|
105
|
-
self.
|
114
|
+
self.MessageFromRecord = self.extension.MessageFromRecord
|
106
115
|
if self.alternating_lines == 1:
|
107
116
|
self.alternating_lines = 0
|
108
117
|
self.background_is_light = False
|
@@ -118,19 +127,18 @@ class generic_handler_t(lggg.Handler):
|
|
118
127
|
if hasattr(record, SHOW_W_RULE_ATTR):
|
119
128
|
message = RuleAsText(record.msg)
|
120
129
|
else:
|
121
|
-
message
|
130
|
+
message = self.MessageFromRecord(record)
|
122
131
|
else:
|
123
132
|
if hasattr(record, SHOW_W_RULE_ATTR):
|
124
133
|
richer = Rule(record.msg, DATE_TIME_COLOR)
|
125
134
|
else:
|
126
|
-
|
135
|
+
message = self.MessageFromRecord(record, PreProcessed=EscapedForRich)
|
127
136
|
should_highlight_back = self.alternating_lines == 1
|
128
137
|
if self.alternating_lines >= 0:
|
129
138
|
self.alternating_lines = (self.alternating_lines + 1) % 2
|
130
139
|
richer = HighlightedVersion(
|
131
140
|
self.console,
|
132
|
-
|
133
|
-
next_s,
|
141
|
+
message,
|
134
142
|
record.levelno,
|
135
143
|
should_highlight_back=should_highlight_back,
|
136
144
|
background_is_light=self.background_is_light,
|
@@ -161,6 +169,16 @@ class generic_handler_t(lggg.Handler):
|
|
161
169
|
|
162
170
|
self.ShowMessage(message)
|
163
171
|
|
172
|
+
def _DisplayRuleAsText(
|
173
|
+
self, /, *, text: str | None = None, color: str = "white"
|
174
|
+
) -> None:
|
175
|
+
""""""
|
176
|
+
self.ShowMessage(RuleAsText(text))
|
177
|
+
|
178
|
+
def _DisplayRule(self, /, *, text: str | None = None, color: str = "white") -> None:
|
179
|
+
""""""
|
180
|
+
self.ShowMessage(Rule(text, color))
|
181
|
+
|
164
182
|
|
165
183
|
"""
|
166
184
|
COPYRIGHT NOTICE
|
@@ -4,7 +4,6 @@ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
|
4
4
|
SEE COPYRIGHT NOTICE BELOW
|
5
5
|
"""
|
6
6
|
|
7
|
-
from logger_36.constant.logger import HIDE_WHERE_KWARG
|
8
7
|
from logger_36.instance.logger import LOGGER
|
9
8
|
from logger_36.task.measure.chronos import ElapsedTime
|
10
9
|
from logger_36.type.logger import logger_t
|
@@ -12,7 +11,7 @@ from logger_36.type.logger import logger_t
|
|
12
11
|
|
13
12
|
def LogElapsedTime(*, logger: logger_t = LOGGER) -> None:
|
14
13
|
""""""
|
15
|
-
logger.info(f"Elapsed Time: {ElapsedTime()}"
|
14
|
+
logger.info(f"Elapsed Time: {ElapsedTime()}")
|
16
15
|
|
17
16
|
|
18
17
|
"""
|
logger_36/catalog/logger/gpu.py
CHANGED
@@ -7,7 +7,6 @@ SEE COPYRIGHT NOTICE BELOW
|
|
7
7
|
import sys as sstm
|
8
8
|
|
9
9
|
from logger_36.constant.error import GPU_LOGGING_ERROR
|
10
|
-
from logger_36.constant.logger import HIDE_WHERE_KWARG
|
11
10
|
from logger_36.instance.logger import LOGGER
|
12
11
|
from logger_36.type.logger import logger_t
|
13
12
|
|
@@ -41,7 +40,6 @@ def LogGPURelatedDetails(*, logger: logger_t = LOGGER) -> None:
|
|
41
40
|
f" Tensorflow: {tsfl.version.VERSION}\n"
|
42
41
|
f" Tensorflow Build: {tsfl.sysconfig.get_build_info()}\n"
|
43
42
|
f" TensorRT: {tsrt.__version__}",
|
44
|
-
**HIDE_WHERE_KWARG,
|
45
43
|
)
|
46
44
|
|
47
45
|
|
@@ -5,11 +5,10 @@ SEE COPYRIGHT NOTICE BELOW
|
|
5
5
|
"""
|
6
6
|
|
7
7
|
from logger_36.config.memory import LENGTH_100, MAX_N_SAMPLES
|
8
|
-
from logger_36.constant.logger import HIDE_WHERE_KWARG
|
9
8
|
from logger_36.constant.memory import storage_units_h
|
10
9
|
from logger_36.instance.logger import LOGGER
|
11
10
|
from logger_36.task.format.memory import FormattedUsage, UsageBar
|
12
|
-
from logger_36.task.format.message import
|
11
|
+
from logger_36.task.format.message import MessageWithActualExpected
|
13
12
|
from logger_36.type.logger import logger_t
|
14
13
|
|
15
14
|
|
@@ -22,7 +21,7 @@ def LogMemoryUsages(
|
|
22
21
|
logger: logger_t = LOGGER,
|
23
22
|
) -> None:
|
24
23
|
""""""
|
25
|
-
if not logger.
|
24
|
+
if not logger.any_handler_stores_memory:
|
26
25
|
return
|
27
26
|
|
28
27
|
where_s, usages = zip(*logger.memory_usages)
|
@@ -34,7 +33,7 @@ def LogMemoryUsages(
|
|
34
33
|
if isinstance(max_n_samples, int):
|
35
34
|
if max_n_samples < 1:
|
36
35
|
raise ValueError(
|
37
|
-
|
36
|
+
MessageWithActualExpected(
|
38
37
|
"Invalid maximum number of samples",
|
39
38
|
actual=max_n_samples,
|
40
39
|
expected=1,
|
@@ -65,7 +64,7 @@ def LogMemoryUsages(
|
|
65
64
|
)
|
66
65
|
plot = "\n".join(plot)
|
67
66
|
|
68
|
-
logger.info(title + plot
|
67
|
+
logger.info(title + plot)
|
69
68
|
|
70
69
|
|
71
70
|
def LogMaximumMemoryUsage(
|
@@ -77,12 +76,10 @@ def LogMaximumMemoryUsage(
|
|
77
76
|
"""
|
78
77
|
unit: b or None=bytes, k=kilo, m=mega, g=giga, a=auto
|
79
78
|
"""
|
80
|
-
if logger.
|
79
|
+
if logger.any_handler_stores_memory:
|
81
80
|
where, max_usage = logger.max_memory_usage_full
|
82
81
|
value, unit = FormattedUsage(max_usage, unit=unit, decimals=decimals)
|
83
|
-
logger.info(
|
84
|
-
f"Max. Memory Usage: {value}{unit} near {where}", **HIDE_WHERE_KWARG
|
85
|
-
)
|
82
|
+
logger.info(f"Max. Memory Usage: {value}{unit} near {where}")
|
86
83
|
|
87
84
|
|
88
85
|
"""
|
@@ -4,7 +4,6 @@ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
|
4
4
|
SEE COPYRIGHT NOTICE BELOW
|
5
5
|
"""
|
6
6
|
|
7
|
-
from logger_36.constant.logger import HIDE_WHERE_KWARG
|
8
7
|
from logger_36.constant.system import MAX_DETAIL_NAME_LENGTH, SYSTEM_DETAILS_AS_DICT
|
9
8
|
from logger_36.instance.logger import LOGGER
|
10
9
|
from logger_36.task.inspection import Modules
|
@@ -35,7 +34,6 @@ def LogSystemDetails(
|
|
35
34
|
f"{details}\n"
|
36
35
|
f" {'Python Modules':>{MAX_DETAIL_NAME_LENGTH}}:\n"
|
37
36
|
f"{modules}",
|
38
|
-
**HIDE_WHERE_KWARG,
|
39
37
|
)
|
40
38
|
|
41
39
|
|
logger_36/config/logger.py
CHANGED
@@ -12,7 +12,7 @@ from logger_36.catalog.handler.file import file_handler_t
|
|
12
12
|
from logger_36.catalog.handler.generic import generic_handler_t
|
13
13
|
from logger_36.constant.handler import HANDLER_CODES, handler_codes_h
|
14
14
|
from logger_36.instance.logger import LOGGER
|
15
|
-
from logger_36.task.format.message import
|
15
|
+
from logger_36.task.format.message import MessageWithActualExpected
|
16
16
|
|
17
17
|
|
18
18
|
def SetLOGLevel(
|
@@ -48,7 +48,7 @@ def SetLOGLevel(
|
|
48
48
|
|
49
49
|
if not found:
|
50
50
|
raise ValueError(
|
51
|
-
|
51
|
+
MessageWithActualExpected(
|
52
52
|
"Handler not found",
|
53
53
|
actual=which,
|
54
54
|
expected=f"{str(HANDLER_CODES)[1:-1]}, or a handler name",
|
logger_36/config/message.py
CHANGED
@@ -4,20 +4,19 @@ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
|
4
4
|
SEE COPYRIGHT NOTICE BELOW
|
5
5
|
"""
|
6
6
|
|
7
|
+
from datetime import timedelta as time_delta_t
|
8
|
+
|
7
9
|
LEVEL_OPENING = "("
|
8
10
|
LEVEL_CLOSING = ")"
|
9
|
-
MESSAGE_MARKER = "|
|
11
|
+
MESSAGE_MARKER = "|"
|
10
12
|
WHERE_SEPARATOR = "@"
|
11
13
|
ELAPSED_TIME_SEPARATOR = "+"
|
12
|
-
MEMORY_SEPARATOR = ":"
|
13
14
|
|
14
15
|
DATE_FORMAT = "%Y-%m-%d"
|
15
16
|
TIME_FORMAT = "%H:%M:%S"
|
16
|
-
|
17
|
-
ELAPSED_TIME_FORMAT = f" {ELAPSED_TIME_SEPARATOR}%(elapsed_time)s"
|
18
|
-
MEMORY_FORMAT = f" {MEMORY_SEPARATOR}%(memory_usage)s"
|
17
|
+
LONG_ENOUGH = time_delta_t(minutes=5)
|
19
18
|
|
20
|
-
ACTUAL_PATTERNS: str = r" Actual="
|
19
|
+
ACTUAL_PATTERNS: tuple[str] = (r" Actual=",)
|
21
20
|
EXPECTED_PATTERNS: str = r" Expected([!<>]?=|: )"
|
22
21
|
|
23
22
|
"""
|
logger_36/constant/logger.py
CHANGED
@@ -8,8 +8,6 @@ import logging as lggg
|
|
8
8
|
import re as regx
|
9
9
|
import typing as h
|
10
10
|
|
11
|
-
from logger_36.constant.record import HIDE_WHERE_ATTR
|
12
|
-
|
13
11
|
LOGGER_NAME = "logger-36"
|
14
12
|
|
15
13
|
# https://docs.python.org/3/library/logging.html#logging.captureWarnings
|
@@ -17,8 +15,6 @@ WARNING_LOGGER_NAME = "py.warnings"
|
|
17
15
|
WARNING_TYPE_PATTERN = r"([^:]+):([0-9]+): ([^:]+): ([^\n]+)\n"
|
18
16
|
WARNING_TYPE_COMPILED_PATTERN = regx.compile(WARNING_TYPE_PATTERN)
|
19
17
|
|
20
|
-
HIDE_WHERE_KWARG = {"extra": {HIDE_WHERE_ATTR: True}}
|
21
|
-
|
22
18
|
# Second version: with self as first parameter.
|
23
19
|
logger_handle_h = (
|
24
20
|
h.Callable[[lggg.LogRecord], None] | h.Callable[[lggg.Logger, lggg.LogRecord], None]
|
logger_36/constant/message.py
CHANGED
@@ -8,6 +8,7 @@ import time
|
|
8
8
|
import typing as h
|
9
9
|
|
10
10
|
from logger_36.config.message import (
|
11
|
+
ELAPSED_TIME_SEPARATOR,
|
11
12
|
LEVEL_CLOSING,
|
12
13
|
LEVEL_OPENING,
|
13
14
|
MESSAGE_MARKER,
|
@@ -15,9 +16,10 @@ from logger_36.config.message import (
|
|
15
16
|
)
|
16
17
|
|
17
18
|
TIME_LENGTH = time.strftime(TIME_FORMAT, time.gmtime(0)).__len__()
|
19
|
+
TIME_LENGTH_m_1 = TIME_LENGTH - ELAPSED_TIME_SEPARATOR.__len__()
|
18
20
|
LOG_LEVEL_LENGTH = 1 + LEVEL_OPENING.__len__() + LEVEL_CLOSING.__len__()
|
19
21
|
CONTEXT_LENGTH = TIME_LENGTH + LOG_LEVEL_LENGTH
|
20
|
-
LINE_INDENT = (CONTEXT_LENGTH + MESSAGE_MARKER.__len__() +
|
22
|
+
LINE_INDENT = (CONTEXT_LENGTH + MESSAGE_MARKER.__len__() + 2) * " "
|
21
23
|
NEXT_LINE_PROLOGUE = "\n" + LINE_INDENT
|
22
24
|
|
23
25
|
expected_op_h = h.Literal[":", ": ", "=", "!=", ">=", "<="]
|
logger_36/constant/record.py
CHANGED
@@ -4,10 +4,9 @@ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
|
|
4
4
|
SEE COPYRIGHT NOTICE BELOW
|
5
5
|
"""
|
6
6
|
|
7
|
-
SHOW_W_RULE_ATTR = "
|
8
|
-
|
9
|
-
HIDE_WHERE_ATTR = "
|
10
|
-
SHOW_MEMORY_ATTR = "show_memory_usage"
|
7
|
+
SHOW_W_RULE_ATTR = "should_show_w_rule"
|
8
|
+
STORE_MEMORY_ATTR = "should_store_memory_usage"
|
9
|
+
HIDE_WHERE_ATTR = "should_hide_where"
|
11
10
|
|
12
11
|
"""
|
13
12
|
COPYRIGHT NOTICE
|
logger_36/content.py
CHANGED
@@ -5,7 +5,7 @@ SEE COPYRIGHT NOTICE BELOW
|
|
5
5
|
"""
|
6
6
|
|
7
7
|
from logger_36.constant.message import LINE_INDENT
|
8
|
-
from logger_36.task.format.message import
|
8
|
+
from logger_36.task.format.message import MessageWithActualExpected
|
9
9
|
from logger_36.task.format.rule import Rule, RuleAsText
|
10
10
|
|
11
11
|
"""
|