logger-36 2024.11__py3-none-any.whl → 2024.13__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.
@@ -47,6 +47,7 @@ class console_handler_t(lggg.Handler):
47
47
  level: dtcl.InitVar[int] = lggg.NOTSET
48
48
  show_where: dtcl.InitVar[bool] = True
49
49
  show_memory_usage: dtcl.InitVar[bool] = False
50
+ message_width: dtcl.InitVar[int] = -1
50
51
  formatter: dtcl.InitVar[lggg.Formatter | None] = None
51
52
 
52
53
  def __post_init__(
@@ -55,6 +56,7 @@ class console_handler_t(lggg.Handler):
55
56
  level: int,
56
57
  show_where: bool,
57
58
  show_memory_usage: bool,
59
+ message_width: int,
58
60
  formatter: lggg.Formatter | None,
59
61
  ) -> None:
60
62
  """"""
@@ -66,6 +68,7 @@ class console_handler_t(lggg.Handler):
66
68
  show_memory_usage=show_memory_usage,
67
69
  handler=self,
68
70
  level=level,
71
+ message_width=message_width,
69
72
  formatter=formatter,
70
73
  )
71
74
 
@@ -82,6 +82,7 @@ class console_rich_handler_t(lggg.Handler):
82
82
  level: dtcl.InitVar[int] = lggg.NOTSET
83
83
  show_where: dtcl.InitVar[bool] = True
84
84
  show_memory_usage: dtcl.InitVar[bool] = False
85
+ message_width: dtcl.InitVar[int] = -1
85
86
  formatter: dtcl.InitVar[lggg.Formatter | None] = None
86
87
  should_install_traceback: dtcl.InitVar[bool] = False
87
88
 
@@ -93,6 +94,7 @@ class console_rich_handler_t(lggg.Handler):
93
94
  level: int,
94
95
  show_where: bool,
95
96
  show_memory_usage: bool,
97
+ message_width: int,
96
98
  formatter: lggg.Formatter | None,
97
99
  should_install_traceback: bool,
98
100
  rich_kwargs: dict[str, h.Any] | None,
@@ -106,6 +108,7 @@ class console_rich_handler_t(lggg.Handler):
106
108
  show_memory_usage=show_memory_usage,
107
109
  handler=self,
108
110
  level=level,
111
+ message_width=message_width,
109
112
  formatter=formatter,
110
113
  )
111
114
 
@@ -49,6 +49,7 @@ class file_handler_t(lggg.FileHandler):
49
49
  level: dtcl.InitVar[int] = lggg.NOTSET
50
50
  show_where: dtcl.InitVar[bool] = True
51
51
  show_memory_usage: dtcl.InitVar[bool] = False
52
+ message_width: dtcl.InitVar[int] = -1
52
53
  formatter: dtcl.InitVar[lggg.Formatter | None] = None
53
54
 
54
55
  path: dtcl.InitVar[path_t | None] = None
@@ -61,6 +62,7 @@ class file_handler_t(lggg.FileHandler):
61
62
  level: int,
62
63
  show_where: bool,
63
64
  show_memory_usage: bool,
65
+ message_width: int,
64
66
  formatter: lggg.Formatter | None,
65
67
  path: path_t | None,
66
68
  handler_args: tuple[h.Any],
@@ -75,6 +77,7 @@ class file_handler_t(lggg.FileHandler):
75
77
  show_memory_usage=show_memory_usage,
76
78
  handler=self,
77
79
  level=level,
80
+ message_width=message_width,
78
81
  formatter=formatter,
79
82
  )
80
83
 
@@ -37,6 +37,7 @@ from logger_36.catalog.config.console_rich import DATE_TIME_COLOR
37
37
 
38
38
  try:
39
39
  from rich.console import Console as console_t
40
+ from rich.console import ConsoleOptions as console_options_t
40
41
  from rich.markup import escape as EscapedForRich
41
42
  from rich.terminal_theme import DEFAULT_TERMINAL_THEME
42
43
  except ModuleNotFoundError:
@@ -60,6 +61,7 @@ class generic_handler_t(lggg.Handler):
60
61
 
61
62
  extension: handler_extension_t = dtcl.field(init=False)
62
63
  console: console_t | None = None
64
+ console_options: console_options_t | None = None
63
65
  FormattedLines: h.Callable[..., tuple[str, str | None]] = dtcl.field(init=False)
64
66
  ShowMessage: h.Callable[[str], None] = lambda _arg: None
65
67
 
@@ -67,6 +69,7 @@ class generic_handler_t(lggg.Handler):
67
69
  level: dtcl.InitVar[int] = lggg.NOTSET
68
70
  show_where: dtcl.InitVar[bool] = True
69
71
  show_memory_usage: dtcl.InitVar[bool] = False
72
+ message_width: dtcl.InitVar[int] = -1
70
73
  formatter: dtcl.InitVar[lggg.Formatter | None] = None
71
74
 
72
75
  supports_html: dtcl.InitVar[bool] = False
@@ -79,6 +82,7 @@ class generic_handler_t(lggg.Handler):
79
82
  level: int,
80
83
  show_where: bool,
81
84
  show_memory_usage: bool,
85
+ message_width: int,
82
86
  formatter: lggg.Formatter | None,
83
87
  supports_html: bool,
84
88
  rich_kwargs: dict[str, h.Any] | None,
@@ -93,6 +97,7 @@ class generic_handler_t(lggg.Handler):
93
97
  show_memory_usage=show_memory_usage,
94
98
  handler=self,
95
99
  level=level,
100
+ message_width=message_width,
96
101
  formatter=formatter,
97
102
  )
98
103
 
@@ -104,6 +109,9 @@ class generic_handler_t(lggg.Handler):
104
109
  force_terminal=True,
105
110
  **rich_kwargs,
106
111
  )
112
+ self.console_options = self.console.options.update(
113
+ overflow="ignore", no_wrap=True
114
+ )
107
115
 
108
116
  self.FormattedLines = self.extension.FormattedLines
109
117
 
@@ -126,7 +134,7 @@ class generic_handler_t(lggg.Handler):
126
134
  richer = console_rich_handler_t.HighlightedVersion(
127
135
  first, next_s, record.levelno
128
136
  )
129
- segments = self.console.render(richer)
137
+ segments = self.console.render(richer, options=self.console_options)
130
138
 
131
139
  # Inspired from the code of: rich.console.export_html.
132
140
  html_segments = []
@@ -36,8 +36,6 @@ WHERE_SEPARATOR = "@"
36
36
  ELAPSED_TIME_SEPARATOR = "+"
37
37
  MEMORY_SEPARATOR = ":"
38
38
 
39
- INTERCEPTED_LOG_SEPARATOR = " >>> "
40
-
41
39
  DATE_FORMAT = "%Y-%m-%d"
42
40
  TIME_FORMAT = "%H:%M:%S"
43
41
  WHERE_FORMAT = f" {WHERE_SEPARATOR} {{module}}:{{funcName}}:{{lineno}}"
logger_36/main.py CHANGED
@@ -62,6 +62,7 @@ def AddGenericHandler(
62
62
  level: int = lggg.INFO,
63
63
  show_where: bool = True,
64
64
  show_memory_usage: bool = False,
65
+ message_width: int = -1,
65
66
  formatter: lggg.Formatter | None = None,
66
67
  supports_html: bool = False,
67
68
  should_hold_messages: bool = False,
@@ -76,6 +77,7 @@ def AddGenericHandler(
76
77
  level=level,
77
78
  show_where=show_where,
78
79
  show_memory_usage=show_memory_usage,
80
+ message_width=message_width,
79
81
  formatter=formatter,
80
82
  supports_html=supports_html,
81
83
  rich_kwargs=kwargs,
@@ -91,6 +93,7 @@ def AddConsoleHandler(
91
93
  level: int = lggg.INFO,
92
94
  show_where: bool = True,
93
95
  show_memory_usage: bool = False,
96
+ message_width: int = -1,
94
97
  formatter: lggg.Formatter | None = None,
95
98
  should_hold_messages: bool = False,
96
99
  ) -> None:
@@ -103,6 +106,7 @@ def AddConsoleHandler(
103
106
  level=level,
104
107
  show_where=show_where,
105
108
  show_memory_usage=show_memory_usage,
109
+ message_width=message_width,
106
110
  formatter=formatter,
107
111
  )
108
112
  logger.AddHandler(handler, should_hold_messages)
@@ -115,6 +119,7 @@ def AddRichConsoleHandler(
115
119
  level: int = lggg.INFO,
116
120
  show_where: bool = True,
117
121
  show_memory_usage: bool = False,
122
+ message_width: int = -1,
118
123
  formatter: lggg.Formatter | None = None,
119
124
  should_hold_messages: bool = False,
120
125
  should_install_traceback: bool = False,
@@ -134,6 +139,7 @@ def AddRichConsoleHandler(
134
139
  level=level,
135
140
  show_where=show_where,
136
141
  show_memory_usage=show_memory_usage,
142
+ message_width=message_width,
137
143
  formatter=formatter,
138
144
  should_install_traceback=should_install_traceback,
139
145
  rich_kwargs=kwargs,
@@ -150,6 +156,7 @@ def AddFileHandler(
150
156
  level: int = lggg.INFO,
151
157
  show_where: bool = True,
152
158
  show_memory_usage: bool = False,
159
+ message_width: int = -1,
153
160
  formatter: lggg.Formatter | None = None,
154
161
  should_hold_messages: bool = False,
155
162
  **kwargs,
@@ -167,6 +174,7 @@ def AddFileHandler(
167
174
  level=level,
168
175
  show_where=show_where,
169
176
  show_memory_usage=show_memory_usage,
177
+ message_width=message_width,
170
178
  formatter=formatter,
171
179
  path=path,
172
180
  handler_args=args,
@@ -53,6 +53,7 @@ class handler_extension_t:
53
53
  name: str | None = None
54
54
  show_where: bool = True
55
55
  show_memory_usage: bool = False
56
+ message_width: int = -1
56
57
  FormattedRecord: h.Callable[[lggg.LogRecord], str] = dtcl.field(init=False)
57
58
 
58
59
  handler: dtcl.InitVar[lggg.Handler | None] = None
@@ -85,6 +86,8 @@ class handler_extension_t:
85
86
 
86
87
  handler.setLevel(level)
87
88
 
89
+ if 0 < self.message_width < 5:
90
+ self.message_width = 5
88
91
  if formatter is None:
89
92
  message_format = MessageFormat(self.show_where, self.show_memory_usage)
90
93
  formatter = lggg.Formatter(fmt=message_format, datefmt=TIME_FORMAT)
@@ -111,13 +114,26 @@ class handler_extension_t:
111
114
 
112
115
  if PreProcessed is not None:
113
116
  message = PreProcessed(message)
114
- if "\n" in message:
115
- lines = message.splitlines()
117
+ if (has_newlines := ("\n" in message)) or (
118
+ (self.message_width > 0) and (message.__len__() > self.message_width)
119
+ ):
120
+ if has_newlines:
121
+ lines = message.splitlines()
122
+ if self.message_width > 0:
123
+ lines = _WrappedLines(lines, self.message_width)
124
+ else:
125
+ lines = _WrappedLines([message], self.message_width)
116
126
  next_lines = NEXT_LINE_PROLOGUE.join(lines[1:])
117
127
  next_lines = f"{NEXT_LINE_PROLOGUE}{next_lines}"
118
128
  message = lines[0]
119
129
  else:
120
130
  next_lines = None
131
+ if self.message_width > 0:
132
+ n_missing_s = self.message_width - message.__len__()
133
+ if n_missing_s > 3:
134
+ message += " " + (n_missing_s - 1) * "."
135
+ elif n_missing_s > 0:
136
+ message += n_missing_s * " "
121
137
 
122
138
  record.msg = message
123
139
  if self.show_where and not hasattr(record, SHOW_WHERE_ATTR):
@@ -152,3 +168,34 @@ class handler_extension_t:
152
168
  return f"{first_line}{next_lines}", None
153
169
  else:
154
170
  return first_line, next_lines
171
+
172
+
173
+ def _WrappedLines(lines: list[str], message_width: int, /) -> list[str]:
174
+ """"""
175
+ output = []
176
+
177
+ for line in lines:
178
+ while line.__len__() > message_width:
179
+ if all(
180
+ _elm != " " for _elm in line[(message_width - 1) : (message_width + 1)]
181
+ ):
182
+ if line[message_width - 2] == " ":
183
+ piece, line = (
184
+ line[: (message_width - 2)].rstrip(),
185
+ line[(message_width - 1) :],
186
+ )
187
+ else:
188
+ piece, line = (
189
+ line[: (message_width - 1)] + "-",
190
+ line[(message_width - 1) :],
191
+ )
192
+ else:
193
+ piece, line = (
194
+ line[:message_width].rstrip(),
195
+ line[message_width:].lstrip(),
196
+ )
197
+ output.append(piece)
198
+
199
+ output.append(line)
200
+
201
+ return output
logger_36/type/logger.py CHANGED
@@ -42,7 +42,7 @@ from pathlib import Path as path_t
42
42
  from traceback import TracebackException as traceback_t
43
43
 
44
44
  from logger_36.config.issue import ISSUE_CONTEXT_END, ISSUE_CONTEXT_SEPARATOR
45
- from logger_36.config.message import DATE_FORMAT, INTERCEPTED_LOG_SEPARATOR
45
+ from logger_36.config.message import DATE_FORMAT
46
46
  from logger_36.constant.generic import NOT_PASSED
47
47
  from logger_36.constant.issue import ORDER, order_h
48
48
  from logger_36.constant.logger import (
@@ -65,13 +65,12 @@ from logger_36.type.issue import NewIssue, issue_t
65
65
 
66
66
  @dtcl.dataclass(slots=True, repr=False, eq=False)
67
67
  class logger_t(lggg.Logger):
68
- # Must not be False until at least one handler has been added.
69
- should_hold_messages: bool = True
70
-
71
68
  name: dtcl.InitVar[str] = LOGGER_NAME
72
69
  level: dtcl.InitVar[int] = lggg.NOTSET
73
70
  activate_wrn_interceptions: dtcl.InitVar[bool] = True
74
71
  exit_on_error: bool = False
72
+ # Must not be False until at least one handler has been added.
73
+ should_hold_messages: bool = True
75
74
 
76
75
  on_hold: list[lggg.LogRecord] = dtcl.field(init=False, default_factory=list)
77
76
  last_message_date: str = dtcl.field(init=False, default="")
@@ -221,7 +220,7 @@ class logger_t(lggg.Logger):
221
220
  date = dttm.now().strftime(DATE_FORMAT)
222
221
  if date != self.last_message_date:
223
222
  self.last_message_date = date
224
- # levelno: Added for management by lggg.Logger.handle.
223
+ # levelno: Added for management by logging.Logger.handle.
225
224
  date_record = lggg.makeLogRecord(
226
225
  {
227
226
  "name": self.name,
@@ -368,7 +367,7 @@ def _HandleForInterceptions(
368
367
 
369
368
  def handle_p(_: lggg.Logger, record: lggg.LogRecord, /) -> None:
370
369
  duplicate = lggg.makeLogRecord(record.__dict__)
371
- duplicate.msg = f"{intercepted.name}{INTERCEPTED_LOG_SEPARATOR}{record.msg}"
370
+ duplicate.msg = f"{record.msg} :{intercepted.name}:"
372
371
  interceptor.handle(duplicate)
373
372
 
374
373
  return handle_p
logger_36/version.py CHANGED
@@ -29,4 +29,4 @@
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
- __version__ = "2024.11"
32
+ __version__ = "2024.13"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: logger-36
3
- Version: 2024.11
3
+ Version: 2024.13
4
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
@@ -1,19 +1,19 @@
1
1
  logger_36/__init__.py,sha256=67ZAWtUx9Qy8Yn-tLQkOIEO6Z9U-8jhfm-tqNjjeFPU,1758
2
2
  logger_36/instance.py,sha256=wAVty29f24SCs4FRL600QySlA_WeLUM78p4t_Ni-LzA,1618
3
- logger_36/main.py,sha256=peXqcSDTrJhlKQkxSmum94BUJ8pIrtWTfvV9hUXp_pU,6558
4
- logger_36/version.py,sha256=VPjT_M7RlFPu1ODt109-IVr0VpM4GYTOMO2BBrkKt0A,1578
3
+ logger_36/main.py,sha256=H0MW3hZXdXHjTnliH8GNJkjqPZITLTaeaNH7lZPPFFI,6822
4
+ logger_36/version.py,sha256=mdgjriUY276JSM3W1EzdgeLIIYLoA17Di2FfkJcKm7Y,1578
5
5
  logger_36/catalog/config/console_rich.py,sha256=XKRKJx_5dxp4mgan1D-u_qrQos-pezRccqKsnmn-ook,2119
6
- logger_36/catalog/handler/console.py,sha256=dm2-_1ZXUd6Gl1uyJaapPhUldzkEZ2fOlgeH8gxmpSs,3094
7
- logger_36/catalog/handler/console_rich.py,sha256=TMP9fupSY8OdGb3jeMAeSLjOssJBgcdwkTDo4Enud5U,6513
8
- logger_36/catalog/handler/file.py,sha256=tBShoy37F3riXDQc802feKzdpHQj5F3vqKaq211I1WI,3509
9
- logger_36/catalog/handler/generic.py,sha256=H0ky_4Ua0_xAXrjtAjVFvSteagdSu1WEXrPKcG4qbRY,6050
6
+ logger_36/catalog/handler/console.py,sha256=_CJcd9WiEQcfDZgcCPSSU_9ZlOqx8jztSuMNKy7bt04,3205
7
+ logger_36/catalog/handler/console_rich.py,sha256=6tCWYe3fuDf10x1Qoobyal-DV9BQjbUWpJ6JvtFZ0Ac,6624
8
+ logger_36/catalog/handler/file.py,sha256=kwRqDgGC8SP9Ojg652a71QzSGjIkerKv_cS7IITqJGE,3620
9
+ logger_36/catalog/handler/generic.py,sha256=xpFnMuG3d9Xr2i5Tu_y8pU2Ohuu6CeZ4oGg5xyHmTtQ,6435
10
10
  logger_36/catalog/logging/chronos.py,sha256=zVe5ZwB63mqNqlIDm6ZBi4-U5n_n-21h8umhimRUcdU,1815
11
11
  logger_36/catalog/logging/gpu.py,sha256=0XqVVK_TV1QPEwGXyK99jThHAjfsf-V__3m9Jh4gewk,2783
12
12
  logger_36/catalog/logging/memory.py,sha256=-5SOXAV43RnXznBPbClVMpMqtMlVtBsI46w6ngz1oP4,4040
13
13
  logger_36/catalog/logging/system.py,sha256=zomL8kRpmQuVP5KkcJkcUTnXK4ah3yn9PJb_cveNZDQ,2449
14
14
  logger_36/config/issue.py,sha256=wAOChQMpGECw-4Jy0TWArOeQ1P134cGyKaVbc6NrwX8,1639
15
15
  logger_36/config/memory.py,sha256=2OvnG7RMM1aZcUWBYGcNoBdLsQguo8cV862vCYSMbQs,1589
16
- logger_36/config/message.py,sha256=ZrR0jE144e88Dy_H5CXfmIAZnNsXH5P6i2VjCKaPU5w,2058
16
+ logger_36/config/message.py,sha256=fTZDkA6N9BBwfcTwRdEliAja0qPZwAdrxMORNFi1WLk,2021
17
17
  logger_36/config/system.py,sha256=i39b-QNbg7i3BW_X-bHH9CqGO6mq1k9Ru5faYPi63SA,1849
18
18
  logger_36/constant/error.py,sha256=mqlzrSdOJkuMxtRQnhNXosiGEYp8KInODBJIIdCNgbE,2197
19
19
  logger_36/constant/generic.py,sha256=s0WHW-R_Eu2doDMoGERX3MtfCHmIW6uDjrDt_qP5MLA,1616
@@ -31,10 +31,10 @@ logger_36/task/format/message.py,sha256=91CCgH7umLHUV_YRf4AyOsYZTgNVOvQSODqXO1wJ
31
31
  logger_36/task/format/rule.py,sha256=cq4jl_ZCb8m7QoX8mWevXhy1hgwncLpc-9woKoT7m24,1970
32
32
  logger_36/task/measure/chronos.py,sha256=7xZskYEXQCPDypmnlhn4KDCBB1v3eL1OE_sv-l3n8Do,2255
33
33
  logger_36/task/measure/memory.py,sha256=aichGI-iCeE3Z4Y8AmWGdal2931IMdcdv4VgCeDLBoI,1876
34
- logger_36/type/extension.py,sha256=W4sS48WiUUQStWq7rt8gZxtilElpfNSVc6cG3j8kfDA,5992
34
+ logger_36/type/extension.py,sha256=U28VqEL3Wq_E_TZ-ZlBAXRyTr9oVPnA6ez7EyHjKM0E,7673
35
35
  logger_36/type/issue.py,sha256=OnkBKRTMsHvZ-2aLQWtBzGSWMTVs_4ermg71Ygcs0w8,2153
36
- logger_36/type/logger.py,sha256=FAaYj3wH9R9mhLNZLkYxjWwviWjDLBp4EilbHZnORJM,13248
37
- logger_36-2024.11.dist-info/METADATA,sha256=JBX4N-jAY_UNB4PpM9VrABAqQx1RA-ZfFyFfFos_T5k,5592
38
- logger_36-2024.11.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
39
- logger_36-2024.11.dist-info/top_level.txt,sha256=sM95BTMWmslEEgR_1pzwZsOeSp8C_QBiu8ImbFr0XLc,10
40
- logger_36-2024.11.dist-info/RECORD,,
36
+ logger_36/type/logger.py,sha256=mBk1Bd7Iunu4utnz8UqBCQRhDW9spLZhBZ2hAH8mTZE,13199
37
+ logger_36-2024.13.dist-info/METADATA,sha256=DD-SjP5m4_DkDUd3V_Ma1W1gJgrCWDjcYYzmx7JjedU,5592
38
+ logger_36-2024.13.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
39
+ logger_36-2024.13.dist-info/top_level.txt,sha256=sM95BTMWmslEEgR_1pzwZsOeSp8C_QBiu8ImbFr0XLc,10
40
+ logger_36-2024.13.dist-info/RECORD,,