logger-36 2024.1__py3-none-any.whl → 2024.3__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 -7
- logger_36/catalog/config/console_rich.py +49 -0
- logger_36/catalog/handler/console.py +80 -0
- logger_36/{type/console.py → catalog/handler/console_rich.py} +77 -52
- logger_36/catalog/handler/file.py +90 -0
- logger_36/catalog/handler/generic.py +150 -0
- logger_36/catalog/logging/chronos.py +39 -0
- logger_36/catalog/{gpu.py → logging/gpu.py} +3 -1
- logger_36/catalog/logging/memory.py +105 -0
- logger_36/catalog/{system.py → logging/system.py} +5 -27
- logger_36/config/issue.py +35 -0
- logger_36/config/memory.py +33 -0
- logger_36/{config.py → config/message.py} +14 -14
- logger_36/config/system.py +49 -0
- logger_36/constant/generic.py +37 -0
- logger_36/constant/handler.py +35 -0
- logger_36/constant/issue.py +35 -0
- logger_36/{type/file.py → constant/logger.py} +13 -15
- logger_36/constant/memory.py +39 -0
- logger_36/{constant.py → constant/message.py} +11 -15
- logger_36/constant/record.py +35 -0
- logger_36/constant/system.py +39 -0
- logger_36/instance.py +5 -5
- logger_36/main.py +130 -32
- logger_36/{catalog → task/format}/memory.py +34 -33
- logger_36/task/format/message.py +112 -0
- logger_36/task/format/rule.py +47 -0
- logger_36/task/inspection.py +18 -18
- logger_36/{measure → task/measure}/chronos.py +4 -2
- logger_36/task/storage.py +64 -3
- logger_36/type/extension.py +73 -61
- logger_36/type/issue.py +57 -0
- logger_36/type/logger.py +346 -0
- logger_36/version.py +1 -1
- {logger_36-2024.1.dist-info → logger_36-2024.3.dist-info}/METADATA +2 -3
- logger_36-2024.3.dist-info/RECORD +39 -0
- {logger_36-2024.1.dist-info → logger_36-2024.3.dist-info}/WHEEL +1 -1
- logger_36/type/generic.py +0 -115
- logger_36-2024.1.dist-info/RECORD +0 -21
- /logger_36/{measure → task/measure}/memory.py +0 -0
- {logger_36-2024.1.dist-info → logger_36-2024.3.dist-info}/top_level.txt +0 -0
logger_36/type/extension.py
CHANGED
@@ -29,94 +29,106 @@
|
|
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
|
+
import dataclasses as dtcl
|
32
33
|
import logging as lggg
|
33
34
|
import sys as sstm
|
34
|
-
|
35
|
+
import typing as h
|
35
36
|
|
36
|
-
from logger_36.
|
37
|
-
from logger_36.
|
38
|
-
from logger_36.constant import
|
39
|
-
from logger_36.
|
40
|
-
from logger_36.
|
37
|
+
from logger_36.config.message import TIME_FORMAT, WHERE_FORMAT
|
38
|
+
from logger_36.constant.handler import HANDLER_CODES
|
39
|
+
from logger_36.constant.memory import MEMORY_MEASURE_ERROR
|
40
|
+
from logger_36.constant.message import NEXT_LINE_PROLOGUE
|
41
|
+
from logger_36.constant.record import HIDE_WHERE_ATTR, SHOW_WHERE_ATTR
|
42
|
+
from logger_36.task.format.message import FormattedMessage, MessageFormat
|
43
|
+
from logger_36.task.measure.chronos import TimeStamp
|
44
|
+
from logger_36.task.measure.memory import CanCheckMemory
|
41
45
|
|
42
46
|
|
47
|
+
@dtcl.dataclass(slots=True, repr=False, eq=False)
|
43
48
|
class handler_extension_t:
|
44
|
-
|
45
|
-
|
46
|
-
show_memory_usage: bool
|
47
|
-
|
48
|
-
exit_on_error: bool
|
49
|
+
name: str | None = None
|
50
|
+
show_where: bool = True
|
51
|
+
show_memory_usage: bool = False
|
52
|
+
FormattedRecord: h.Callable[[lggg.LogRecord], str] = dtcl.field(init=False)
|
49
53
|
|
50
|
-
|
54
|
+
handler: dtcl.InitVar[lggg.Handler | None] = None
|
55
|
+
level: dtcl.InitVar[int] = lggg.NOTSET
|
56
|
+
formatter: dtcl.InitVar[lggg.Formatter | None] = None
|
57
|
+
|
58
|
+
def __post_init__(
|
59
|
+
self, handler: lggg.Handler | None, level: int, formatter: lggg.Formatter | None
|
60
|
+
) -> None:
|
51
61
|
""""""
|
52
|
-
self.
|
53
|
-
|
54
|
-
|
55
|
-
|
62
|
+
if self.name in HANDLER_CODES:
|
63
|
+
raise ValueError(
|
64
|
+
FormattedMessage(
|
65
|
+
"Invalid handler name",
|
66
|
+
actual=self.name,
|
67
|
+
expected=f"a name not in {str(HANDLER_CODES)[1:-1]}",
|
68
|
+
)
|
69
|
+
)
|
70
|
+
|
71
|
+
if self.name is None:
|
72
|
+
self.name = TimeStamp()
|
73
|
+
|
74
|
+
if self.show_memory_usage and not CanCheckMemory():
|
75
|
+
self.show_memory_usage = False
|
76
|
+
print(MEMORY_MEASURE_ERROR, file=sstm.stderr)
|
77
|
+
|
78
|
+
handler.setLevel(level)
|
56
79
|
|
57
|
-
|
80
|
+
if formatter is None:
|
81
|
+
message_format = MessageFormat(self.show_where, self.show_memory_usage)
|
82
|
+
formatter = lggg.Formatter(fmt=message_format, datefmt=TIME_FORMAT)
|
83
|
+
handler.setFormatter(formatter)
|
84
|
+
self.FormattedRecord = handler.formatter.format
|
85
|
+
|
86
|
+
def FormattedLines(
|
58
87
|
self,
|
59
88
|
record: lggg.LogRecord,
|
60
89
|
/,
|
61
90
|
*,
|
62
|
-
PreProcessed: Callable[[str], str] | None = None,
|
63
|
-
|
91
|
+
PreProcessed: h.Callable[[str], str] | None = None,
|
92
|
+
should_join_lines: bool = False,
|
64
93
|
) -> tuple[str, str | None]:
|
65
94
|
"""
|
66
|
-
|
67
|
-
Use "msg" instead.
|
95
|
+
See logger_36.catalog.handler.README.txt.
|
68
96
|
"""
|
69
|
-
|
70
|
-
|
97
|
+
record.level_first_letter = record.levelname[0]
|
98
|
+
|
99
|
+
message = record.msg
|
100
|
+
if not isinstance(message, str):
|
101
|
+
message = str(message)
|
102
|
+
original_message = message
|
103
|
+
|
71
104
|
if PreProcessed is not None:
|
72
|
-
|
73
|
-
if "\n" in
|
74
|
-
|
75
|
-
lines = original_message.splitlines()
|
76
|
-
record.msg = lines[0]
|
105
|
+
message = PreProcessed(message)
|
106
|
+
if "\n" in message:
|
107
|
+
lines = message.splitlines()
|
77
108
|
next_lines = NEXT_LINE_PROLOGUE.join(lines[1:])
|
78
109
|
next_lines = f"{NEXT_LINE_PROLOGUE}{next_lines}"
|
110
|
+
message = lines[0]
|
79
111
|
else:
|
80
|
-
|
81
|
-
|
82
|
-
# The record is shared between handlers, so do not re-assign if already there.
|
83
|
-
if not hasattr(record, "elapsed_time"):
|
84
|
-
record.elapsed_time = ElapsedTime()
|
85
|
-
# Re-assign for each handler in case they have different show properties.
|
86
|
-
if self.show_memory_usage:
|
87
|
-
record.memory_usage = self.FormattedMemoryUsage()
|
88
|
-
else:
|
89
|
-
record.memory_usage = ""
|
112
|
+
next_lines = None
|
90
113
|
|
91
|
-
|
92
|
-
|
114
|
+
record.msg = message
|
115
|
+
if self.show_where and not hasattr(record, SHOW_WHERE_ATTR):
|
116
|
+
hide_where = getattr(record, HIDE_WHERE_ATTR, False)
|
117
|
+
if hide_where:
|
118
|
+
record.where = ""
|
119
|
+
else:
|
120
|
+
record.where = WHERE_FORMAT.format(
|
121
|
+
module=record.module, funcName=record.funcName, lineno=record.lineno
|
122
|
+
)
|
123
|
+
first_line = self.FormattedRecord(record).replace("\t", " ")
|
93
124
|
|
94
125
|
# Revert the record message to its original value for subsequent handlers.
|
95
|
-
|
96
|
-
record.msg = original_message
|
126
|
+
record.msg = original_message
|
97
127
|
|
98
|
-
if
|
128
|
+
if should_join_lines:
|
99
129
|
if next_lines is None:
|
100
130
|
return first_line, None
|
101
131
|
else:
|
102
132
|
return f"{first_line}{next_lines}", None
|
103
133
|
else:
|
104
134
|
return first_line, next_lines
|
105
|
-
|
106
|
-
def FormattedMemoryUsage(self) -> str:
|
107
|
-
""""""
|
108
|
-
if self.show_memory_usage:
|
109
|
-
usage = CurrentMemoryUsage()
|
110
|
-
if usage > self.max_memory_usage:
|
111
|
-
self.max_memory_usage = usage
|
112
|
-
|
113
|
-
usage, unit = MemoryWithAutoUnit(usage, 1)
|
114
|
-
|
115
|
-
return f" :{usage}{unit}"
|
116
|
-
else:
|
117
|
-
return ""
|
118
|
-
|
119
|
-
def ExitOrNotIfError(self, record: lggg.LogRecord, /) -> None:
|
120
|
-
""""""
|
121
|
-
if self.exit_on_error and (record.levelno in (lggg.ERROR, lggg.CRITICAL)):
|
122
|
-
sstm.exit(1)
|
logger_36/type/issue.py
ADDED
@@ -0,0 +1,57 @@
|
|
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 typing as h
|
33
|
+
|
34
|
+
from logger_36.config.issue import ISSUE_BASE_CONTEXT
|
35
|
+
from logger_36.constant.generic import NOT_PASSED
|
36
|
+
from logger_36.task.format.message import FormattedMessage
|
37
|
+
|
38
|
+
issue_t = str
|
39
|
+
|
40
|
+
|
41
|
+
def NewIssue(
|
42
|
+
context: str,
|
43
|
+
separator: str,
|
44
|
+
message: str,
|
45
|
+
/,
|
46
|
+
*,
|
47
|
+
actual: h.Any = NOT_PASSED,
|
48
|
+
expected: h.Any | None = None,
|
49
|
+
) -> issue_t:
|
50
|
+
""""""
|
51
|
+
if context.__len__() == 0:
|
52
|
+
context = ISSUE_BASE_CONTEXT
|
53
|
+
message = FormattedMessage(
|
54
|
+
message, actual=actual, expected=expected, with_final_dot=False
|
55
|
+
)
|
56
|
+
|
57
|
+
return f"{context}{separator}{message}"
|
logger_36/type/logger.py
ADDED
@@ -0,0 +1,346 @@
|
|
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.issue import ISSUE_CONTEXT_END, ISSUE_CONTEXT_SEPARATOR
|
44
|
+
from logger_36.config.message import DATE_FORMAT, INTERCEPTED_LOG_SEPARATOR
|
45
|
+
from logger_36.constant.generic import NOT_PASSED
|
46
|
+
from logger_36.constant.issue import ORDER, order_h
|
47
|
+
from logger_36.constant.logger import (
|
48
|
+
HIDE_WHERE_KWARG,
|
49
|
+
LOGGER_NAME,
|
50
|
+
WARNING_LOGGER_NAME,
|
51
|
+
WARNING_TYPE_COMPILED_PATTERN,
|
52
|
+
logger_handle_h,
|
53
|
+
)
|
54
|
+
from logger_36.constant.record import SHOW_MEMORY_ATTR, SHOW_W_RULE_ATTR
|
55
|
+
from logger_36.task.format.memory import (
|
56
|
+
FormattedUsageWithAutoUnit as FormattedMemoryUsage,
|
57
|
+
)
|
58
|
+
from logger_36.task.format.message import FormattedMessage
|
59
|
+
from logger_36.task.measure.chronos import ElapsedTime
|
60
|
+
from logger_36.task.measure.memory import CurrentUsage as CurrentMemoryUsage
|
61
|
+
from logger_36.type.issue import NewIssue, issue_t
|
62
|
+
|
63
|
+
|
64
|
+
@dtcl.dataclass(slots=True, repr=False, eq=False)
|
65
|
+
class logger_t(lggg.Logger):
|
66
|
+
# Must not be False until at least one handler has been added.
|
67
|
+
should_hold_messages: bool = True
|
68
|
+
|
69
|
+
name: dtcl.InitVar[str] = LOGGER_NAME
|
70
|
+
level: dtcl.InitVar[int] = lggg.NOTSET
|
71
|
+
activate_wrn_interceptions: dtcl.InitVar[bool] = True
|
72
|
+
exit_on_error: bool = False
|
73
|
+
|
74
|
+
on_hold: list[lggg.LogRecord] = dtcl.field(init=False, default_factory=list)
|
75
|
+
last_message_date: str = dtcl.field(init=False, default="")
|
76
|
+
any_handler_shows_memory: bool = dtcl.field(init=False, default=False)
|
77
|
+
memory_usages: list[tuple[str, int]] = dtcl.field(init=False, default_factory=list)
|
78
|
+
context_levels: list[str] = dtcl.field(init=False, default_factory=list)
|
79
|
+
staged_issues: list[issue_t] = dtcl.field(init=False, default_factory=list)
|
80
|
+
intercepted_wrn_handle: logger_handle_h | None = dtcl.field(
|
81
|
+
init=False, default=None
|
82
|
+
)
|
83
|
+
intercepted_log_handles: dict[str, logger_handle_h] = dtcl.field(
|
84
|
+
init=False, default_factory=dict
|
85
|
+
)
|
86
|
+
|
87
|
+
def __post_init__(
|
88
|
+
self, name: str, level: int, activate_wrn_interceptions: bool
|
89
|
+
) -> None:
|
90
|
+
""""""
|
91
|
+
lggg.Logger.__init__(self, name)
|
92
|
+
self.setLevel(level)
|
93
|
+
self.propagate = False
|
94
|
+
|
95
|
+
if activate_wrn_interceptions:
|
96
|
+
self._ActivateWarningInterceptions()
|
97
|
+
|
98
|
+
def _ActivateWarningInterceptions(self) -> None:
|
99
|
+
"""
|
100
|
+
The log message will not appear if called from __post_init__ since there are no
|
101
|
+
handlers yet.
|
102
|
+
"""
|
103
|
+
if self.intercepted_wrn_handle is None:
|
104
|
+
logger = lggg.getLogger(WARNING_LOGGER_NAME)
|
105
|
+
|
106
|
+
self.intercepted_wrn_handle = logger.handle
|
107
|
+
logger.handle = t.MethodType(_HandleForWarnings(self), logger)
|
108
|
+
|
109
|
+
lggg.captureWarnings(True)
|
110
|
+
self.info("Warning Interception: ON", **HIDE_WHERE_KWARG)
|
111
|
+
|
112
|
+
def _DeactivateWarningInterceptions(self) -> None:
|
113
|
+
""""""
|
114
|
+
if self.intercepted_wrn_handle is not None:
|
115
|
+
logger = lggg.getLogger(WARNING_LOGGER_NAME)
|
116
|
+
|
117
|
+
logger.handle = self.intercepted_wrn_handle
|
118
|
+
self.intercepted_wrn_handle = None
|
119
|
+
|
120
|
+
lggg.captureWarnings(False)
|
121
|
+
self.info("Warning Interception: OFF", **HIDE_WHERE_KWARG)
|
122
|
+
|
123
|
+
def ToggleWarningInterceptions(self, state: bool, /) -> None:
|
124
|
+
""""""
|
125
|
+
if state:
|
126
|
+
self._ActivateWarningInterceptions()
|
127
|
+
else:
|
128
|
+
self._DeactivateWarningInterceptions()
|
129
|
+
|
130
|
+
def ToggleLogInterceptions(self, state: bool, /) -> None:
|
131
|
+
""""""
|
132
|
+
if state:
|
133
|
+
self.ToggleLogInterceptions(False)
|
134
|
+
|
135
|
+
all_loggers = [lggg.getLogger()] + [
|
136
|
+
lggg.getLogger(_nme)
|
137
|
+
for _nme in self.manager.loggerDict
|
138
|
+
if _nme not in (self.name, WARNING_LOGGER_NAME)
|
139
|
+
]
|
140
|
+
for logger in all_loggers:
|
141
|
+
self.intercepted_log_handles[logger.name] = logger.handle
|
142
|
+
logger.handle = t.MethodType(
|
143
|
+
_HandleForInterceptions(logger, self), logger
|
144
|
+
)
|
145
|
+
|
146
|
+
intercepted = sorted(self.intercepted_log_handles.keys())
|
147
|
+
if intercepted.__len__() > 0:
|
148
|
+
self.info(
|
149
|
+
f"Now Intercepting LOGs from: {str(intercepted)[1:-1]}",
|
150
|
+
**HIDE_WHERE_KWARG,
|
151
|
+
)
|
152
|
+
elif self.intercepted_log_handles.__len__() > 0:
|
153
|
+
for name, handle in self.intercepted_log_handles.items():
|
154
|
+
logger = lggg.getLogger(name)
|
155
|
+
logger.handle = handle
|
156
|
+
self.intercepted_log_handles.clear()
|
157
|
+
self.info("Log Interception: OFF", **HIDE_WHERE_KWARG)
|
158
|
+
|
159
|
+
@property
|
160
|
+
def max_memory_usage(self) -> int:
|
161
|
+
""""""
|
162
|
+
return max(tuple(zip(*self.memory_usages))[1])
|
163
|
+
|
164
|
+
@property
|
165
|
+
def max_memory_usage_full(self) -> tuple[str, int]:
|
166
|
+
""""""
|
167
|
+
where_s, usages = zip(*self.memory_usages)
|
168
|
+
max_usage = max(usages)
|
169
|
+
|
170
|
+
return where_s[usages.index(max_usage)], max_usage
|
171
|
+
|
172
|
+
def AddHandler(self, handler: lggg.Handler, should_hold_messages: bool, /) -> None:
|
173
|
+
""""""
|
174
|
+
self.should_hold_messages = should_hold_messages
|
175
|
+
lggg.Logger.addHandler(self, handler)
|
176
|
+
|
177
|
+
extension = getattr(handler, "extension", None)
|
178
|
+
if extension is None:
|
179
|
+
show_memory_usage = False
|
180
|
+
else:
|
181
|
+
show_memory_usage = getattr(extension, SHOW_MEMORY_ATTR, False)
|
182
|
+
if show_memory_usage:
|
183
|
+
self.any_handler_shows_memory = True
|
184
|
+
|
185
|
+
extension = getattr(handler, "extension", handler.name)
|
186
|
+
if isinstance(extension, str):
|
187
|
+
name = extension
|
188
|
+
else:
|
189
|
+
name = getattr(extension, "name", "Anonymous")
|
190
|
+
self.info(
|
191
|
+
f'New handler "{name}" with class "{type(handler).__name__}" and '
|
192
|
+
f"level {lggg.getLevelName(handler.level)}",
|
193
|
+
**HIDE_WHERE_KWARG,
|
194
|
+
)
|
195
|
+
|
196
|
+
def handle(self, record: lggg.LogRecord, /) -> None:
|
197
|
+
""""""
|
198
|
+
if (not self.should_hold_messages) and (self.on_hold.__len__() > 0):
|
199
|
+
for hold in self.on_hold:
|
200
|
+
lggg.Logger.handle(self, hold)
|
201
|
+
self.on_hold.clear()
|
202
|
+
|
203
|
+
record.elapsed_time = ElapsedTime()
|
204
|
+
|
205
|
+
if self.any_handler_shows_memory or not self.hasHandlers():
|
206
|
+
# Memory usage is also added if there are no handlers yet, just in case.
|
207
|
+
usage = CurrentMemoryUsage()
|
208
|
+
self.memory_usages.append(
|
209
|
+
(f"{record.module}.{record.funcName}.{record.lineno}", usage)
|
210
|
+
)
|
211
|
+
|
212
|
+
value, unit = FormattedMemoryUsage(usage, 1)
|
213
|
+
record.memory_usage = f"{value}{unit}"
|
214
|
+
|
215
|
+
date = dttm.now().strftime(DATE_FORMAT)
|
216
|
+
if date != self.last_message_date:
|
217
|
+
self.last_message_date = date
|
218
|
+
# levelno is added for management by lggg.Logger.handle.
|
219
|
+
date_record = lggg.makeLogRecord(
|
220
|
+
{
|
221
|
+
"levelno": lggg.INFO,
|
222
|
+
"msg": f"DATE: {date}",
|
223
|
+
SHOW_W_RULE_ATTR: True,
|
224
|
+
}
|
225
|
+
)
|
226
|
+
if self.should_hold_messages:
|
227
|
+
self.on_hold.append(date_record)
|
228
|
+
else:
|
229
|
+
lggg.Logger.handle(self, date_record)
|
230
|
+
|
231
|
+
if self.should_hold_messages:
|
232
|
+
self.on_hold.append(record)
|
233
|
+
else:
|
234
|
+
lggg.Logger.handle(self, record)
|
235
|
+
|
236
|
+
if self.exit_on_error and (record.levelno in (lggg.ERROR, lggg.CRITICAL)):
|
237
|
+
sstm.exit(1)
|
238
|
+
|
239
|
+
def AddContextLevel(self, new_level: str, /) -> None:
|
240
|
+
""""""
|
241
|
+
self.context_levels.append(new_level)
|
242
|
+
|
243
|
+
def AddedContextLevel(self, new_level: str, /) -> logger_t:
|
244
|
+
"""
|
245
|
+
Meant to be used as:
|
246
|
+
with self.AddedContextLevel("new level"):
|
247
|
+
...
|
248
|
+
"""
|
249
|
+
self.AddContextLevel(new_level)
|
250
|
+
return self
|
251
|
+
|
252
|
+
def StageIssue(
|
253
|
+
self,
|
254
|
+
message: str,
|
255
|
+
/,
|
256
|
+
*,
|
257
|
+
actual: h.Any = NOT_PASSED,
|
258
|
+
expected: h.Any | None = None,
|
259
|
+
) -> None:
|
260
|
+
""""""
|
261
|
+
context = ISSUE_CONTEXT_SEPARATOR.join(self.context_levels)
|
262
|
+
issue = NewIssue(
|
263
|
+
context, ISSUE_CONTEXT_END, message, actual=actual, expected=expected
|
264
|
+
)
|
265
|
+
self.staged_issues.append(issue)
|
266
|
+
|
267
|
+
@property
|
268
|
+
def has_staged_issues(self) -> bool:
|
269
|
+
""""""
|
270
|
+
return self.staged_issues.__len__() > 0
|
271
|
+
|
272
|
+
def CommitIssues(
|
273
|
+
self,
|
274
|
+
level: int,
|
275
|
+
/,
|
276
|
+
*,
|
277
|
+
order: order_h = "when",
|
278
|
+
) -> None:
|
279
|
+
""""""
|
280
|
+
if not self.has_staged_issues:
|
281
|
+
return
|
282
|
+
|
283
|
+
if order not in ORDER:
|
284
|
+
raise ValueError(
|
285
|
+
FormattedMessage(
|
286
|
+
"Invalid commit order",
|
287
|
+
actual=order,
|
288
|
+
expected=f"One of {str(ORDER)[1:-1]}",
|
289
|
+
)
|
290
|
+
)
|
291
|
+
|
292
|
+
if order == "when":
|
293
|
+
issues = self.staged_issues
|
294
|
+
else: # order == "context"
|
295
|
+
issues = sorted(self.staged_issues, key=lambda _elm: _elm.context)
|
296
|
+
issues = "\n".join(issues)
|
297
|
+
|
298
|
+
self.log(level, issues, **HIDE_WHERE_KWARG)
|
299
|
+
self.staged_issues.clear()
|
300
|
+
|
301
|
+
def __enter__(self) -> None:
|
302
|
+
""""""
|
303
|
+
pass
|
304
|
+
|
305
|
+
def __exit__(
|
306
|
+
self,
|
307
|
+
exc_type: Exception | None,
|
308
|
+
exc_value: str | None,
|
309
|
+
traceback: traceback_t | None,
|
310
|
+
/,
|
311
|
+
) -> bool:
|
312
|
+
""""""
|
313
|
+
_ = self.context_levels.pop()
|
314
|
+
return False
|
315
|
+
|
316
|
+
|
317
|
+
def _HandleForWarnings(interceptor: lggg.Logger, /) -> logger_handle_h:
|
318
|
+
""""""
|
319
|
+
|
320
|
+
def handle_p(_: lggg.Logger, record: lggg.LogRecord, /) -> None:
|
321
|
+
pieces = WARNING_TYPE_COMPILED_PATTERN.match(record.msg).group
|
322
|
+
module = path_t(pieces(1)).stem
|
323
|
+
line = pieces(2)
|
324
|
+
kind = pieces(3)
|
325
|
+
message = pieces(4)
|
326
|
+
duplicate = lggg.makeLogRecord(record.__dict__)
|
327
|
+
duplicate.msg = f"{kind}: {message}"
|
328
|
+
duplicate.module = module
|
329
|
+
duplicate.funcName = "<function>"
|
330
|
+
duplicate.lineno = line
|
331
|
+
interceptor.handle(duplicate)
|
332
|
+
|
333
|
+
return handle_p
|
334
|
+
|
335
|
+
|
336
|
+
def _HandleForInterceptions(
|
337
|
+
intercepted: lggg.Logger, interceptor: lggg.Logger, /
|
338
|
+
) -> logger_handle_h:
|
339
|
+
""""""
|
340
|
+
|
341
|
+
def handle_p(_: lggg.Logger, record: lggg.LogRecord, /) -> None:
|
342
|
+
duplicate = lggg.makeLogRecord(record.__dict__)
|
343
|
+
duplicate.msg = f"{intercepted.name}{INTERCEPTED_LOG_SEPARATOR}{record.msg}"
|
344
|
+
interceptor.handle(duplicate)
|
345
|
+
|
346
|
+
return handle_p
|
logger_36/version.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: logger-36
|
3
|
-
Version: 2024.
|
4
|
-
Summary: Simple logger
|
3
|
+
Version: 2024.3
|
4
|
+
Summary: Simple logger with a catalog of handlers
|
5
5
|
Home-page: https://src.koda.cnrs.fr/eric.debreuve/logger-36/
|
6
6
|
Author: Eric Debreuve
|
7
7
|
Author-email: eric.debreuve@cnrs.fr
|
@@ -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=qsHEd1MYxDfYmVO_dHrGsY9g8pdcOEwb2wSkuVGS1ws,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=fxlAFmJVAdUZQVDYvkVFC7hGsL01tIx4GaB5UG4M-tY,1637
|
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=BsaNdtVx9XF-Pt_V7rqP6UKyJ7G03_gX1FVM7mnBay0,5026
|
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=T1WFtc8Js1OChYkIHQiOP825Dcb9atpEprLWaPTxAHA,2151
|
35
|
+
logger_36/type/logger.py,sha256=eoSFZL4b8vB370bcfi0QUa_xsjZXwUoxDy_M38vawZQ,12187
|
36
|
+
logger_36-2024.3.dist-info/METADATA,sha256=SCsGBauGyMu7xto-BNhLCGLB3xFm9-ZVw2zl9OgYEZA,4236
|
37
|
+
logger_36-2024.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
38
|
+
logger_36-2024.3.dist-info/top_level.txt,sha256=sM95BTMWmslEEgR_1pzwZsOeSp8C_QBiu8ImbFr0XLc,10
|
39
|
+
logger_36-2024.3.dist-info/RECORD,,
|