festo-python-logging 0.0.7__tar.gz → 0.0.10__tar.gz

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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: festo-python-logging
3
- Version: 0.0.7
3
+ Version: 0.0.10
4
4
  Summary: Convenience function to configure python logging.
5
5
  License: Proprietary
6
6
  Author: Charles Wilmot
@@ -14,3 +14,4 @@ Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
15
  Classifier: Programming Language :: Python :: 3.12
16
16
  Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
@@ -4,6 +4,8 @@ from datetime import datetime
4
4
  from pathlib import Path
5
5
  from typing import List, Optional
6
6
 
7
+ from festo_python_logging.formatter import AlignedFormatter
8
+
7
9
 
8
10
  def configure_logging(
9
11
  verbose: bool = False,
@@ -23,10 +25,7 @@ def configure_logging(
23
25
 
24
26
  """
25
27
  # Define formatters for stdout and file logging
26
- stdout_formatter = logging.Formatter(
27
- fmt="{relativeCreated:13.2f} {levelname:>8} {name:>35.35}:{lineno:4d} │ {message}",
28
- style="{",
29
- )
28
+ stdout_formatter = AlignedFormatter()
30
29
  file_formatter = logging.Formatter(
31
30
  fmt="{relativeCreated:13.2f} {levelname:>8} {name:>35.35}:{lineno:4d} │ {message}",
32
31
  style="{",
@@ -0,0 +1,52 @@
1
+ import logging
2
+ import shutil
3
+ import textwrap
4
+
5
+
6
+ class AlignedFormatter(logging.Formatter):
7
+ """A logging formatter that aligns log messages for better readability."""
8
+
9
+ def format(self, record): # noqa: D102, manually set below
10
+ if not hasattr(self, "_max_record_name_length"):
11
+ self._max_record_name_length = 8
12
+
13
+ if len(record.name) > self._max_record_name_length:
14
+ self._max_record_name_length = min(35, len(record.name))
15
+
16
+ # Get the base message
17
+ message = record.getMessage()
18
+ separator_1 = "├"
19
+ separator_2 = "│"
20
+
21
+ # Compute available width for message text
22
+ terminal_width = shutil.get_terminal_size((160, 20)).columns
23
+
24
+ right_padded_record_name = f"{record.name:>{self._max_record_name_length}.{self._max_record_name_length}}"
25
+ prefix = (
26
+ " ".join(
27
+ (
28
+ f"{record.relativeCreated:13.2f}",
29
+ f"{record.levelname:>8}",
30
+ f"{right_padded_record_name}:{record.lineno:4d}",
31
+ ),
32
+ )
33
+ + f" {separator_1} "
34
+ )
35
+ text_width = max(10, terminal_width - len(prefix))
36
+
37
+ # Wrap the message text
38
+ wrapped_lines = textwrap.wrap(message, width=text_width)
39
+
40
+ # Assemble aligned output
41
+ if wrapped_lines:
42
+ lines = [prefix + wrapped_lines[0]]
43
+ continuation_prefix = " " * (len(prefix) - 2) + separator_2 + " "
44
+ for line in wrapped_lines[1:]:
45
+ lines.append(continuation_prefix + line)
46
+ formatted = "\n".join(lines)
47
+ else:
48
+ formatted = prefix
49
+
50
+ return formatted
51
+
52
+ format.__doc__ = logging.Formatter.format.__doc__
@@ -0,0 +1,20 @@
1
+ import logging
2
+
3
+ from festo_python_logging import configure_logging
4
+
5
+ logger = logging.getLogger(__name__)
6
+
7
+ configure_logging(verbose=True)
8
+
9
+ logger.debug("This is a debug message.")
10
+ logger.info("This is an info message.")
11
+ logger.warning("This is a warning message.")
12
+ logger.error("This is an error message.")
13
+
14
+ verys = "very " * 50
15
+ logger.debug(f"This is a {verys} long debug message.")
16
+ logger.info(f"This is an {verys} long info message.")
17
+ logger.warning(f"This is a {verys} long warning message.")
18
+ logger.error(f"This is an {verys} long error message.")
19
+ some_list = [i for i in range(100)]
20
+ logger.debug(f"{some_list}")
@@ -5,7 +5,7 @@ build-backend = "poetry_dynamic_versioning.backend"
5
5
 
6
6
  [tool.poetry]
7
7
  name = "festo-python-logging"
8
- version = "0.0.7"
8
+ version = "0.0.10"
9
9
  license = "Proprietary"
10
10
  authors = [
11
11
  "Charles Wilmot <charles.wilmot@festo.com>",
@@ -56,7 +56,9 @@ ignore = [
56
56
  "ANN401", # at the moment a lot of these annotations are necessary due to missing upstream typing support,
57
57
  "D100", # not enforced pending decision on documentation requirements
58
58
  "D104", # not enforced pending decision on documentation requirements
59
+ "D107", # missing docstring in __init__
59
60
  "D401", # Do not enforce first word being in impertative
61
+ "D203", # 1 blank line before class docstring
60
62
  "D211",
61
63
  "D213",
62
64
  "TRY003", # raise-vanilla-args