logger-36 2023.13__py3-none-any.whl → 2025.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 +65 -41
- logger_36/api/logger.py +53 -0
- logger_36/api/storage.py +53 -0
- logger_36/catalog/config/console_rich.py +76 -0
- logger_36/catalog/handler/console.py +117 -0
- logger_36/catalog/handler/console_rich.py +235 -0
- logger_36/catalog/handler/file.py +128 -0
- logger_36/catalog/handler/generic.py +228 -0
- logger_36/catalog/logger/chronos.py +61 -0
- logger_36/catalog/logger/gpu.py +90 -0
- logger_36/catalog/logger/memory.py +129 -0
- logger_36/catalog/logger/system.py +84 -0
- logger_36/config/issue.py +56 -0
- logger_36/config/logger.py +103 -0
- logger_36/config/memory.py +54 -0
- logger_36/config/message.py +66 -0
- logger_36/config/system.py +70 -0
- logger_36/constant/error.py +70 -0
- logger_36/constant/generic.py +58 -0
- logger_36/constant/handler.py +58 -0
- logger_36/constant/issue.py +58 -0
- logger_36/constant/logger.py +67 -0
- logger_36/constant/memory.py +58 -0
- logger_36/constant/message.py +72 -0
- logger_36/constant/record.py +55 -0
- logger_36/constant/system.py +60 -0
- logger_36/content.py +55 -0
- logger_36/exception.py +105 -0
- logger_36/gpu.py +53 -0
- logger_36/handler.py +209 -0
- logger_36/instance/logger.py +55 -0
- logger_36/instance/loggers.py +56 -0
- logger_36/memory.py +60 -0
- logger_36/storage.py +53 -0
- logger_36/system.py +53 -0
- logger_36/task/format/memory.py +132 -0
- logger_36/task/format/message.py +111 -0
- logger_36/task/format/rule.py +74 -0
- logger_36/task/inspection.py +70 -48
- logger_36/task/measure/chronos.py +84 -0
- logger_36/task/measure/memory.py +72 -0
- logger_36/task/storage.py +164 -0
- logger_36/time.py +54 -0
- logger_36/type/handler.py +184 -0
- logger_36/type/issue.py +91 -0
- logger_36/type/logger.py +542 -0
- logger_36/type/loggers.py +78 -0
- logger_36/version.py +53 -32
- logger_36-2025.3.dist-info/METADATA +154 -0
- logger_36-2025.3.dist-info/RECORD +52 -0
- {logger_36-2023.13.dist-info → logger_36-2025.3.dist-info}/WHEEL +1 -1
- logger_36/config.py +0 -66
- logger_36/constant.py +0 -57
- logger_36/main.py +0 -185
- logger_36/measure/chronos.py +0 -55
- logger_36/measure/memory.py +0 -102
- logger_36/type/console.py +0 -122
- logger_36/type/extension.py +0 -122
- logger_36/type/file.py +0 -52
- logger_36/type/generic.py +0 -116
- logger_36-2023.13.dist-info/METADATA +0 -106
- logger_36-2023.13.dist-info/RECORD +0 -16
- {logger_36-2023.13.dist-info → logger_36-2025.3.dist-info}/top_level.txt +0 -0
logger_36/measure/memory.py
DELETED
@@ -1,102 +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
|
-
from typing import Literal
|
33
|
-
|
34
|
-
try:
|
35
|
-
from psutil import Process as process_t
|
36
|
-
|
37
|
-
_PROCESS = process_t()
|
38
|
-
_KILO_UNIT = 1024.0
|
39
|
-
_MEGA_UNIT = _KILO_UNIT * 1024.0
|
40
|
-
_GIGA_UNIT = _MEGA_UNIT * 1024.0
|
41
|
-
except ModuleNotFoundError:
|
42
|
-
_PROCESS = None
|
43
|
-
_KILO_UNIT = _MEGA_UNIT = _GIGA_UNIT = 0.0
|
44
|
-
|
45
|
-
|
46
|
-
def CanCheckMemory() -> bool:
|
47
|
-
""""""
|
48
|
-
return _PROCESS is not None
|
49
|
-
|
50
|
-
|
51
|
-
def CurrentUsage() -> int:
|
52
|
-
""""""
|
53
|
-
return _PROCESS.memory_info().rss
|
54
|
-
|
55
|
-
|
56
|
-
def FormattedUsage(
|
57
|
-
usage: int,
|
58
|
-
/,
|
59
|
-
*,
|
60
|
-
unit: Literal["b", "k", "m", "g", "a"] | None = "a",
|
61
|
-
decimals: int = None,
|
62
|
-
) -> tuple[int | float, str]:
|
63
|
-
"""
|
64
|
-
unit: b or None=bytes, k=kilo, m=mega, g=giga, a=auto
|
65
|
-
"""
|
66
|
-
if (unit is None) or (unit == "b"):
|
67
|
-
unit = "B"
|
68
|
-
elif unit == "k":
|
69
|
-
usage = _Rounded(usage / _KILO_UNIT, decimals)
|
70
|
-
unit = "KB"
|
71
|
-
elif unit == "m":
|
72
|
-
usage = _Rounded(usage / _MEGA_UNIT, decimals)
|
73
|
-
unit = "MB"
|
74
|
-
elif unit == "g":
|
75
|
-
usage = _Rounded(usage / _GIGA_UNIT, decimals)
|
76
|
-
unit = "GB"
|
77
|
-
elif unit == "a":
|
78
|
-
usage, unit = WithAutoUnit(usage, decimals)
|
79
|
-
|
80
|
-
return usage, unit
|
81
|
-
|
82
|
-
|
83
|
-
def WithAutoUnit(usage: int, decimals: int | None, /) -> tuple[int | float, str]:
|
84
|
-
""""""
|
85
|
-
if usage > _GIGA_UNIT:
|
86
|
-
return _Rounded(usage / _GIGA_UNIT, decimals), "GB"
|
87
|
-
|
88
|
-
if usage > _MEGA_UNIT:
|
89
|
-
return _Rounded(usage / _MEGA_UNIT, decimals), "MB"
|
90
|
-
|
91
|
-
if usage > _KILO_UNIT:
|
92
|
-
return _Rounded(usage / _KILO_UNIT, decimals), "KB"
|
93
|
-
|
94
|
-
return usage, "B"
|
95
|
-
|
96
|
-
|
97
|
-
def _Rounded(value: float, decimals: int | None, /) -> int | float:
|
98
|
-
""""""
|
99
|
-
if decimals == 0:
|
100
|
-
decimals = None
|
101
|
-
|
102
|
-
return round(value, ndigits=decimals)
|
logger_36/type/console.py
DELETED
@@ -1,122 +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 ClassVar
|
34
|
-
|
35
|
-
from rich.color import Color as color_t
|
36
|
-
from rich.console import Console as console_t
|
37
|
-
from rich.markup import escape as PreProcessedForRich
|
38
|
-
from rich.style import Style as style_t
|
39
|
-
from rich.text import Text as text_t
|
40
|
-
|
41
|
-
from logger_36.config import ELAPSED_TIME_SEPARATOR, LEVEL_CLOSING, WHERE_SEPARATOR
|
42
|
-
from logger_36.constant import DATE_TIME_LENGTH
|
43
|
-
from logger_36.type.extension import handler_extension_t
|
44
|
-
|
45
|
-
|
46
|
-
class console_handler_t(lggg.Handler, handler_extension_t):
|
47
|
-
TAB_SIZE: ClassVar[int] = 5 # => CONTEXT_SEPARATOR aligned for all log levels.
|
48
|
-
DATE_TIME_COLOR: ClassVar[str] = "dodger_blue2"
|
49
|
-
LEVEL_COLOR: ClassVar[dict[int, str | style_t]] = {
|
50
|
-
lggg.DEBUG: "orchid",
|
51
|
-
lggg.INFO: "white",
|
52
|
-
lggg.WARNING: "yellow",
|
53
|
-
lggg.ERROR: "orange1",
|
54
|
-
lggg.CRITICAL: "red",
|
55
|
-
}
|
56
|
-
ELAPSED_TIME_COLOR: ClassVar[str] = "green"
|
57
|
-
ACTUAL_COLOR: ClassVar[str] = "red"
|
58
|
-
EXPECTED_COLOR: ClassVar[str] = "green"
|
59
|
-
GRAY_STYLE: ClassVar[style_t] = style_t(color=color_t.from_rgb(150, 150, 150))
|
60
|
-
ACTUAL_PATTERNS: ClassVar[tuple[str]] = (r" Actual=[^.]+;",)
|
61
|
-
EXPECTED_PATTERNS: ClassVar[tuple[str]] = (r" Expected([!<>]=|: )[^.]+\.",)
|
62
|
-
|
63
|
-
console: console_t
|
64
|
-
|
65
|
-
def __init__(self, /, *, level: int = lggg.NOTSET) -> None:
|
66
|
-
""""""
|
67
|
-
lggg.Handler.__init__(self, level=level)
|
68
|
-
handler_extension_t.__init__(self)
|
69
|
-
|
70
|
-
self.setFormatter(self.formatter)
|
71
|
-
self.console = console_t(
|
72
|
-
tab_size=self.__class__.TAB_SIZE,
|
73
|
-
highlight=False,
|
74
|
-
force_terminal=True,
|
75
|
-
record=True,
|
76
|
-
)
|
77
|
-
|
78
|
-
def emit(self, record: lggg.LogRecord, /) -> None:
|
79
|
-
""""""
|
80
|
-
first_line, next_lines = self.MessageLines(
|
81
|
-
record, PreProcessed=PreProcessedForRich
|
82
|
-
)
|
83
|
-
highlighted = self.__class__.HighlightedVersion(
|
84
|
-
first_line, next_lines, record.levelno
|
85
|
-
)
|
86
|
-
self.console.print(highlighted, crop=False, overflow="ignore")
|
87
|
-
|
88
|
-
self.ExitOrNotIfError(record)
|
89
|
-
|
90
|
-
@classmethod
|
91
|
-
def HighlightedVersion(
|
92
|
-
cls, first_line: str, next_lines: str | None, log_level: int, /
|
93
|
-
) -> text_t:
|
94
|
-
""""""
|
95
|
-
output = text_t(first_line)
|
96
|
-
|
97
|
-
# Used instead of _CONTEXT_LENGTH which might include \t, thus creating a
|
98
|
-
# mismatch between character length and length when displayed in console.
|
99
|
-
context_end = first_line.find(LEVEL_CLOSING)
|
100
|
-
elapsed_time_separator = first_line.rfind(ELAPSED_TIME_SEPARATOR)
|
101
|
-
where_separator = first_line.rfind(
|
102
|
-
WHERE_SEPARATOR, context_end, elapsed_time_separator
|
103
|
-
)
|
104
|
-
|
105
|
-
output.stylize(cls.DATE_TIME_COLOR, end=DATE_TIME_LENGTH)
|
106
|
-
output.stylize(
|
107
|
-
cls.LEVEL_COLOR[log_level],
|
108
|
-
start=DATE_TIME_LENGTH,
|
109
|
-
end=context_end + 1,
|
110
|
-
)
|
111
|
-
output.stylize(
|
112
|
-
cls.GRAY_STYLE, start=where_separator, end=elapsed_time_separator
|
113
|
-
)
|
114
|
-
output.stylize(cls.ELAPSED_TIME_COLOR, start=elapsed_time_separator)
|
115
|
-
|
116
|
-
if next_lines is not None:
|
117
|
-
output.append(next_lines)
|
118
|
-
|
119
|
-
output.highlight_words(cls.ACTUAL_PATTERNS, style=cls.ACTUAL_COLOR)
|
120
|
-
output.highlight_words(cls.EXPECTED_PATTERNS, style=cls.EXPECTED_COLOR)
|
121
|
-
|
122
|
-
return output
|
logger_36/type/extension.py
DELETED
@@ -1,122 +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
|
-
import sys as sstm
|
34
|
-
from typing import Callable
|
35
|
-
|
36
|
-
from logger_36.config import DATE_TIME_FORMAT, MESSAGE_FORMAT
|
37
|
-
from logger_36.constant import LOG_LEVEL_LENGTH, NEXT_LINE_PROLOGUE
|
38
|
-
from logger_36.measure.chronos import ElapsedTime
|
39
|
-
from logger_36.measure.memory import CurrentUsage as CurrentMemoryUsage
|
40
|
-
from logger_36.measure.memory import WithAutoUnit as MemoryWithAutoUnit
|
41
|
-
|
42
|
-
|
43
|
-
class handler_extension_t:
|
44
|
-
__slots__ = ("formatter", "show_memory_usage", "max_memory_usage", "exit_on_error")
|
45
|
-
formatter: lggg.Formatter
|
46
|
-
show_memory_usage: bool
|
47
|
-
max_memory_usage: int
|
48
|
-
exit_on_error: bool
|
49
|
-
|
50
|
-
def __init__(self) -> None:
|
51
|
-
""""""
|
52
|
-
self.formatter = lggg.Formatter(fmt=MESSAGE_FORMAT, datefmt=DATE_TIME_FORMAT)
|
53
|
-
self.show_memory_usage = False
|
54
|
-
self.max_memory_usage = -1
|
55
|
-
self.exit_on_error = False
|
56
|
-
|
57
|
-
def MessageLines(
|
58
|
-
self,
|
59
|
-
record: lggg.LogRecord,
|
60
|
-
/,
|
61
|
-
*,
|
62
|
-
PreProcessed: Callable[[str], str] | None = None,
|
63
|
-
should_fully_format: bool = False,
|
64
|
-
) -> tuple[str, str | None]:
|
65
|
-
"""
|
66
|
-
Note: "message" is not yet an attribute of record (it will be set by format());
|
67
|
-
Use "msg" instead.
|
68
|
-
"""
|
69
|
-
if not isinstance(record.msg, str):
|
70
|
-
record.msg = str(record.msg)
|
71
|
-
if PreProcessed is not None:
|
72
|
-
record.msg = PreProcessed(record.msg)
|
73
|
-
if "\n" in record.msg:
|
74
|
-
original_message = record.msg
|
75
|
-
lines = original_message.splitlines()
|
76
|
-
record.msg = lines[0]
|
77
|
-
next_lines = NEXT_LINE_PROLOGUE.join(lines[1:])
|
78
|
-
next_lines = f"{NEXT_LINE_PROLOGUE}{next_lines}"
|
79
|
-
else:
|
80
|
-
original_message = next_lines = None
|
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 = ""
|
90
|
-
|
91
|
-
padding = (LOG_LEVEL_LENGTH - record.levelname.__len__() - 1) * " "
|
92
|
-
first_line = self.formatter.format(record).replace("\t", padding)
|
93
|
-
|
94
|
-
# Revert the record message to its original value for subsequent handlers.
|
95
|
-
if original_message is not None:
|
96
|
-
record.msg = original_message
|
97
|
-
|
98
|
-
if should_fully_format:
|
99
|
-
if next_lines is None:
|
100
|
-
return first_line, None
|
101
|
-
else:
|
102
|
-
return f"{first_line}{next_lines}", None
|
103
|
-
else:
|
104
|
-
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/file.py
DELETED
@@ -1,52 +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 pathlib import Path as path_t
|
34
|
-
|
35
|
-
from logger_36.type.extension import handler_extension_t
|
36
|
-
|
37
|
-
|
38
|
-
class file_handler_t(lggg.FileHandler, handler_extension_t):
|
39
|
-
def __init__(self, path: str | path_t, /, *args, **kwargs) -> None:
|
40
|
-
""""""
|
41
|
-
lggg.FileHandler.__init__(self, str(path), *args, **kwargs)
|
42
|
-
handler_extension_t.__init__(self)
|
43
|
-
|
44
|
-
self.setFormatter(self.formatter)
|
45
|
-
|
46
|
-
def emit(self, record: lggg.LogRecord, /) -> None:
|
47
|
-
""""""
|
48
|
-
message, _ = self.MessageLines(record, should_fully_format=True)
|
49
|
-
print(message, file=self.stream)
|
50
|
-
self.stream.flush()
|
51
|
-
|
52
|
-
self.ExitOrNotIfError(record)
|
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,106 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: logger-36
|
3
|
-
Version: 2023.13
|
4
|
-
Summary: Simple logger using rich_
|
5
|
-
Home-page: https://src.koda.cnrs.fr/eric.debreuve/logger-36/
|
6
|
-
Author: Eric Debreuve
|
7
|
-
Author-email: eric.debreuve@cnrs.fr
|
8
|
-
License: CeCILL-2.1
|
9
|
-
Project-URL: Documentation, https://src.koda.cnrs.fr/eric.debreuve/logger-36//-/wikis/home
|
10
|
-
Project-URL: Source, https://src.koda.cnrs.fr/eric.debreuve/logger-36/
|
11
|
-
Keywords: log,warning,error
|
12
|
-
Classifier: Topic :: Software Development
|
13
|
-
Classifier: Intended Audience :: Developers
|
14
|
-
Classifier: License :: OSI Approved :: CEA CNRS Inria Logiciel Libre License, version 2.1 (CeCILL-2.1)
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
16
|
-
Classifier: Development Status :: 4 - Beta
|
17
|
-
Requires-Python: >=3.10
|
18
|
-
Description-Content-Type: text/x-rst
|
19
|
-
Requires-Dist: rich
|
20
|
-
|
21
|
-
..
|
22
|
-
Copyright CNRS/Inria/UCA
|
23
|
-
Contributor(s): Eric Debreuve (since 2023)
|
24
|
-
|
25
|
-
eric.debreuve@cnrs.fr
|
26
|
-
|
27
|
-
This software is governed by the CeCILL license under French law and
|
28
|
-
abiding by the rules of distribution of free software. You can use,
|
29
|
-
modify and/ or redistribute the software under the terms of the CeCILL
|
30
|
-
license as circulated by CEA, CNRS and INRIA at the following URL
|
31
|
-
"http://www.cecill.info".
|
32
|
-
|
33
|
-
As a counterpart to the access to the source code and rights to copy,
|
34
|
-
modify and redistribute granted by the license, users are provided only
|
35
|
-
with a limited warranty and the software's author, the holder of the
|
36
|
-
economic rights, and the successive licensors have only limited
|
37
|
-
liability.
|
38
|
-
|
39
|
-
In this respect, the user's attention is drawn to the risks associated
|
40
|
-
with loading, using, modifying and/or developing or reproducing the
|
41
|
-
software by the user in light of its specific status of free software,
|
42
|
-
that may mean that it is complicated to manipulate, and that also
|
43
|
-
therefore means that it is reserved for developers and experienced
|
44
|
-
professionals having in-depth computer knowledge. Users are therefore
|
45
|
-
encouraged to load and test the software's suitability as regards their
|
46
|
-
requirements in conditions enabling the security of their systems and/or
|
47
|
-
data to be ensured and, more generally, to use and operate it in the
|
48
|
-
same conditions as regards security.
|
49
|
-
|
50
|
-
The fact that you are presently reading this means that you have had
|
51
|
-
knowledge of the CeCILL license and that you accept its terms.
|
52
|
-
|
53
|
-
.. |PROJECT_NAME| replace:: logger-36
|
54
|
-
.. |SHORT_DESCRIPTION| replace:: Simple logger using ``rich_``
|
55
|
-
|
56
|
-
.. |PYPI_NAME_LITERAL| replace:: ``logger-36``
|
57
|
-
.. |PYPI_PROJECT_URL| replace:: https://pypi.org/project/logger-36/
|
58
|
-
.. _PYPI_PROJECT_URL: https://pypi.org/project/logger-36/
|
59
|
-
|
60
|
-
.. |DOCUMENTATION_URL| replace:: https://src.koda.cnrs.fr/eric.debreuve/logger-36/-/wikis/home
|
61
|
-
.. _DOCUMENTATION_URL: https://src.koda.cnrs.fr/eric.debreuve/logger-36/-/wikis/home
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
===================================
|
66
|
-
|PROJECT_NAME|: |SHORT_DESCRIPTION|
|
67
|
-
===================================
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
Installation
|
72
|
-
============
|
73
|
-
|
74
|
-
This project is published
|
75
|
-
on the `Python Package Index (PyPI) <https://pypi.org/>`_
|
76
|
-
at: |PYPI_PROJECT_URL|_.
|
77
|
-
It should be installable from Python distribution platforms or Integrated Development Environments (IDEs).
|
78
|
-
Otherwise, it can be installed from a command console:
|
79
|
-
|
80
|
-
- For all users, after acquiring administrative rights:
|
81
|
-
- First installation: ``pip install`` |PYPI_NAME_LITERAL|
|
82
|
-
- Installation update: ``pip install --upgrade`` |PYPI_NAME_LITERAL|
|
83
|
-
- For the current user (no administrative rights required):
|
84
|
-
- First installation: ``pip install --user`` |PYPI_NAME_LITERAL|
|
85
|
-
- Installation update: ``pip install --user --upgrade`` |PYPI_NAME_LITERAL|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
Documentation
|
90
|
-
=============
|
91
|
-
|
92
|
-
The documentation is available at |DOCUMENTATION_URL|_.
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
Acknowledgments
|
97
|
-
===============
|
98
|
-
|
99
|
-
The project is developed with `PyCharm Community <https://www.jetbrains.com/pycharm/>`_.
|
100
|
-
|
101
|
-
The development relies on several open-source packages
|
102
|
-
(see ``install_requires`` in ``setup.py``, if present; otherwise ``import`` statements should be searched for).
|
103
|
-
|
104
|
-
The code is formatted by `Black <https://github.com/psf/black/>`_, *The Uncompromising Code Formatter*.
|
105
|
-
|
106
|
-
The imports are ordered by `isort <https://github.com/timothycrosley/isort/>`_... *your imports, so you don't have to*.
|
@@ -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,,
|
File without changes
|