logger-36 2023.13__py3-none-any.whl → 2024.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. logger_36/__init__.py +3 -6
  2. logger_36/catalog/config/console_rich.py +49 -0
  3. logger_36/catalog/handler/console.py +80 -0
  4. logger_36/{type/console.py → catalog/handler/console_rich.py} +77 -52
  5. logger_36/catalog/handler/file.py +90 -0
  6. logger_36/catalog/handler/generic.py +150 -0
  7. logger_36/catalog/logging/chronos.py +39 -0
  8. logger_36/catalog/logging/gpu.py +58 -0
  9. logger_36/catalog/logging/memory.py +105 -0
  10. logger_36/catalog/logging/system.py +62 -0
  11. logger_36/config/issue.py +32 -0
  12. logger_36/config/memory.py +33 -0
  13. logger_36/config/message.py +48 -0
  14. logger_36/{config.py → config/system.py} +0 -17
  15. logger_36/constant/generic.py +37 -0
  16. logger_36/constant/handler.py +35 -0
  17. logger_36/constant/issue.py +35 -0
  18. logger_36/{type/file.py → constant/logger.py} +13 -15
  19. logger_36/constant/memory.py +39 -0
  20. logger_36/{constant.py → constant/message.py} +11 -20
  21. logger_36/constant/record.py +35 -0
  22. logger_36/constant/system.py +39 -0
  23. logger_36/instance.py +34 -0
  24. logger_36/main.py +133 -124
  25. logger_36/{measure → task/format}/memory.py +35 -27
  26. logger_36/task/format/message.py +112 -0
  27. logger_36/task/format/rule.py +47 -0
  28. logger_36/task/inspection.py +18 -18
  29. logger_36/{measure → task/measure}/chronos.py +4 -2
  30. logger_36/task/measure/memory.py +50 -0
  31. logger_36/task/storage.py +144 -0
  32. logger_36/type/extension.py +73 -61
  33. logger_36/type/issue.py +57 -0
  34. logger_36/type/logger.py +349 -0
  35. logger_36/version.py +1 -1
  36. {logger_36-2023.13.dist-info → logger_36-2024.2.dist-info}/METADATA +1 -2
  37. logger_36-2024.2.dist-info/RECORD +39 -0
  38. {logger_36-2023.13.dist-info → logger_36-2024.2.dist-info}/WHEEL +1 -1
  39. logger_36/type/generic.py +0 -116
  40. logger_36-2023.13.dist-info/RECORD +0 -16
  41. {logger_36-2023.13.dist-info → logger_36-2024.2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,105 @@
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 logger_36.config.memory import LENGTH_100, MAX_N_SAMPLES
33
+ from logger_36.constant.logger import HIDE_WHERE_KWARG
34
+ from logger_36.constant.memory import storage_units_h
35
+ from logger_36.instance import LOGGER
36
+ from logger_36.task.format.memory import FormattedUsage, UsageBar
37
+ from logger_36.task.format.message import FormattedMessage
38
+
39
+
40
+ def LogMemoryUsages(
41
+ *,
42
+ unit: storage_units_h | None = "a",
43
+ decimals: int = None,
44
+ max_n_samples: int | None = MAX_N_SAMPLES,
45
+ length_100: int = LENGTH_100,
46
+ ) -> None:
47
+ """"""
48
+ if not LOGGER.any_handler_shows_memory:
49
+ return
50
+
51
+ where_s, usages = zip(*LOGGER.memory_usages)
52
+
53
+ where, max_usage = LOGGER.max_memory_usage_full
54
+ value, unit = FormattedUsage(max_usage, unit=unit, decimals=decimals)
55
+ title = f"Memory Usage: Max={value}{unit} near {where}\n"
56
+
57
+ if isinstance(max_n_samples, int):
58
+ if max_n_samples < 1:
59
+ raise ValueError(
60
+ FormattedMessage(
61
+ "Invalid maximum number of samples",
62
+ actual=max_n_samples,
63
+ expected=1,
64
+ expected_op=">=",
65
+ )
66
+ )
67
+
68
+ where_s = list(where_s)
69
+ usages = list(usages)
70
+ while usages.__len__() > max_n_samples:
71
+ index = usages.index(min(usages))
72
+ del where_s[index]
73
+ del usages[index]
74
+
75
+ usages = tuple(round(_elm, 1) for _elm in usages)
76
+ max_usage = max(usages)
77
+
78
+ plot = []
79
+ max_where_length = max(map(len, where_s))
80
+ usages_as_str = tuple(map(lambda _elm: f"{_elm:_}", usages))
81
+ max_usage_length = max(map(len, usages_as_str))
82
+ for where, usage, usage_as_str in zip(where_s, usages, usages_as_str):
83
+ bar = UsageBar(usage, max_usage, length_100=length_100)
84
+ plot.append(
85
+ f"{where:{max_where_length}} "
86
+ f"{bar:{length_100}} "
87
+ f"{usage_as_str: >{max_usage_length}}"
88
+ )
89
+ plot = "\n".join(plot)
90
+
91
+ LOGGER.info(title + plot, **HIDE_WHERE_KWARG)
92
+
93
+
94
+ def LogMaximumMemoryUsage(
95
+ *, unit: storage_units_h | None = "a", decimals: int = None
96
+ ) -> None:
97
+ """
98
+ unit: b or None=bytes, k=kilo, m=mega, g=giga, a=auto
99
+ """
100
+ if LOGGER.any_handler_shows_memory:
101
+ where, max_usage = LOGGER.max_memory_usage_full
102
+ value, unit = FormattedUsage(max_usage, unit=unit, decimals=decimals)
103
+ LOGGER.info(
104
+ f"Max. Memory Usage: {value}{unit} near {where}", **HIDE_WHERE_KWARG
105
+ )
@@ -0,0 +1,62 @@
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 logger_36.constant.logger import HIDE_WHERE_KWARG
33
+ from logger_36.constant.system import MAX_DETAIL_NAME_LENGTH, SYSTEM_DETAILS_AS_DICT
34
+ from logger_36.instance import LOGGER
35
+ from logger_36.task.inspection import Modules
36
+
37
+
38
+ def LogSystemDetails(
39
+ *,
40
+ modules_with_version: bool = True,
41
+ modules_formatted: bool = True,
42
+ should_restrict_modules_to_loaded: bool = True,
43
+ ) -> None:
44
+ """"""
45
+ details = "\n".join(
46
+ f" {_key:>{MAX_DETAIL_NAME_LENGTH}}: {_vle}"
47
+ for _key, _vle in SYSTEM_DETAILS_AS_DICT.items()
48
+ )
49
+ modules = Modules(
50
+ modules_with_version,
51
+ modules_formatted,
52
+ only_loaded=should_restrict_modules_to_loaded,
53
+ indent=4,
54
+ )
55
+
56
+ LOGGER.info(
57
+ f"SYSTEM DETAILS\n"
58
+ f"{details}\n"
59
+ f" {'Python Modules':>{MAX_DETAIL_NAME_LENGTH}}:\n"
60
+ f"{modules}",
61
+ **HIDE_WHERE_KWARG,
62
+ )
@@ -0,0 +1,32 @@
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
+ BASE_CONTEXT = "BASE"
@@ -0,0 +1,33 @@
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
+ MAX_N_SAMPLES = 10
33
+ LENGTH_100 = 20
@@ -0,0 +1,48 @@
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
+ LEVEL_OPENING = "("
33
+ LEVEL_CLOSING = ")"
34
+ MESSAGE_MARKER = "| "
35
+ WHERE_SEPARATOR = "@"
36
+ ELAPSED_TIME_SEPARATOR = "+"
37
+ MEMORY_SEPARATOR = ":"
38
+
39
+ INTERCEPTED_LOG_SEPARATOR = " >>> "
40
+
41
+ DATE_FORMAT = "%Y-%m-%d"
42
+ TIME_FORMAT = "%H:%M:%S"
43
+ WHERE_FORMAT = f" {WHERE_SEPARATOR} {{module}}:{{funcName}}:{{lineno}}"
44
+ ELAPSED_TIME_FORMAT = f" {ELAPSED_TIME_SEPARATOR}%(elapsed_time)s"
45
+ MEMORY_FORMAT = f" {MEMORY_SEPARATOR}%(memory_usage)s"
46
+
47
+ ACTUAL_PATTERNS: str = r" Actual="
48
+ EXPECTED_PATTERNS: str = r" Expected([!<>]?=|: )"
@@ -29,23 +29,6 @@
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
- LOGGER_NAME = "logger-36"
33
-
34
- LEVEL_OPENING = "["
35
- LEVEL_CLOSING = "]"
36
- CONTEXT_SEPARATOR = "- "
37
- WHERE_SEPARATOR = "@"
38
- ELAPSED_TIME_SEPARATOR = "+"
39
- MESSAGE_FORMAT = (
40
- f"%(asctime)s{LEVEL_OPENING}%(levelname)s{LEVEL_CLOSING}\t"
41
- f"{CONTEXT_SEPARATOR}"
42
- f"%(message)s "
43
- f"{WHERE_SEPARATOR} %(module)s:%(funcName)s:%(lineno)d "
44
- f"{ELAPSED_TIME_SEPARATOR}%(elapsed_time)s"
45
- f"%(memory_usage)s"
46
- )
47
- DATE_TIME_FORMAT = "%Y-%m-%d@%H:%M:%S"
48
-
49
32
  SYSTEM_DETAILS = (
50
33
  "node",
51
34
  "machine",
@@ -0,0 +1,37 @@
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
+
33
+ class _not_passed_t:
34
+ pass
35
+
36
+
37
+ NOT_PASSED = _not_passed_t()
@@ -0,0 +1,35 @@
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
+ handler_codes_h = h.Literal["g", "c", "f", "a"]
35
+ HANDLER_CODES: tuple[str, ...] = h.get_args(handler_codes_h)
@@ -0,0 +1,35 @@
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
+ order_h = h.Literal["when", "context"]
35
+ ORDER: tuple[str, ...] = h.get_args(order_h)
@@ -30,23 +30,21 @@
30
30
  # knowledge of the CeCILL license and that you accept its terms.
31
31
 
32
32
  import logging as lggg
33
- from pathlib import Path as path_t
33
+ import re as regx
34
+ import typing as h
34
35
 
35
- from logger_36.type.extension import handler_extension_t
36
+ from logger_36.constant.record import HIDE_WHERE_ATTR
36
37
 
38
+ LOGGER_NAME = "logger-36"
37
39
 
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)
40
+ # https://docs.python.org/3/library/logging.html#logging.captureWarnings
41
+ WARNING_LOGGER_NAME = "py.warnings"
42
+ WARNING_TYPE_PATTERN = r"([^:]+):([0-9]+): ([^:]+): ([^\n]+)\n"
43
+ WARNING_TYPE_COMPILED_PATTERN = regx.compile(WARNING_TYPE_PATTERN)
43
44
 
44
- self.setFormatter(self.formatter)
45
+ HIDE_WHERE_KWARG = {"extra": {HIDE_WHERE_ATTR: True}}
45
46
 
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)
47
+ # Second version: with self as first parameter.
48
+ logger_handle_h = (
49
+ h.Callable[[lggg.LogRecord], None] | h.Callable[[lggg.Logger, lggg.LogRecord], None]
50
+ )
@@ -0,0 +1,39 @@
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
+ storage_units_h = h.Literal["b", "k", "m", "g", "a"]
35
+ STORAGE_UNITS: tuple[str, ...] = h.get_args(storage_units_h)
36
+
37
+ MEMORY_MEASURE_ERROR = (
38
+ "Cannot show memory usage: " 'Package "psutil" not installed or importable.'
39
+ )
@@ -29,29 +29,20 @@
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 platform as pltf
33
- from datetime import datetime as dttm
32
+ import time
33
+ import typing as h
34
34
 
35
- from logger_36.config import (
36
- CONTEXT_SEPARATOR,
37
- DATE_TIME_FORMAT,
35
+ from logger_36.config.message import (
38
36
  LEVEL_CLOSING,
39
37
  LEVEL_OPENING,
40
- SYSTEM_DETAILS,
38
+ MESSAGE_MARKER,
39
+ TIME_FORMAT,
41
40
  )
42
41
 
43
- # This module is certainly imported early. Therefore, the current time should be close
44
- # enough to the real start time.
45
- START_TIME = dttm.now()
42
+ TIME_LENGTH = time.strftime(TIME_FORMAT, time.gmtime(0)).__len__()
43
+ LOG_LEVEL_LENGTH = 1 + LEVEL_OPENING.__len__() + LEVEL_CLOSING.__len__()
44
+ CONTEXT_LENGTH = TIME_LENGTH + LOG_LEVEL_LENGTH
45
+ NEXT_LINE_PROLOGUE = "\n" + (CONTEXT_LENGTH + MESSAGE_MARKER.__len__() + 1) * " "
46
46
 
47
- DATE_TIME_LENGTH = START_TIME.strftime(DATE_TIME_FORMAT).__len__()
48
- LOG_LEVEL_LENGTH = (
49
- max(map(len, ("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL")))
50
- + LEVEL_OPENING.__len__()
51
- + LEVEL_CLOSING.__len__()
52
- )
53
- CONTEXT_LENGTH = DATE_TIME_LENGTH + LOG_LEVEL_LENGTH
54
- NEXT_LINE_PROLOGUE = "\n" + (CONTEXT_LENGTH + CONTEXT_SEPARATOR.__len__() + 1) * " "
55
-
56
- SYSTEM_DETAILS = {_dtl.capitalize(): getattr(pltf, _dtl)() for _dtl in SYSTEM_DETAILS}
57
- MAX_DETAIL_NAME_LENGTH = max(map(len, SYSTEM_DETAILS.keys()))
47
+ expected_op_h = h.Literal[": ", "=", "!=", ">=", "<="]
48
+ EXPECTED_OP: tuple[str, ...] = h.get_args(expected_op_h)
@@ -0,0 +1,35 @@
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
+ SHOW_W_RULE_ATTR = "show_w_rule"
33
+ SHOW_WHERE_ATTR = "where"
34
+ HIDE_WHERE_ATTR = "hide_where"
35
+ SHOW_MEMORY_ATTR = "show_memory_usage"
@@ -0,0 +1,39 @@
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 platform as pltf
33
+
34
+ from logger_36.config.system import SYSTEM_DETAILS
35
+
36
+ SYSTEM_DETAILS_AS_DICT = {
37
+ _dtl.capitalize(): getattr(pltf, _dtl)() for _dtl in SYSTEM_DETAILS
38
+ }
39
+ MAX_DETAIL_NAME_LENGTH = max(map(len, SYSTEM_DETAILS_AS_DICT.keys()))
logger_36/instance.py ADDED
@@ -0,0 +1,34 @@
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 logger_36.type.logger import logger_t
33
+
34
+ LOGGER = logger_t()