festo-python-logging 0.0.7__py3-none-any.whl → 0.0.10__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.
- festo_python_logging/__init__.py +3 -4
- festo_python_logging/formatter.py +52 -0
- festo_python_logging/test.py +20 -0
- {festo_python_logging-0.0.7.dist-info → festo_python_logging-0.0.10.dist-info}/METADATA +3 -2
- festo_python_logging-0.0.10.dist-info/RECORD +6 -0
- {festo_python_logging-0.0.7.dist-info → festo_python_logging-0.0.10.dist-info}/WHEEL +1 -1
- festo_python_logging-0.0.7.dist-info/RECORD +0 -4
festo_python_logging/__init__.py
CHANGED
|
@@ -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 =
|
|
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}")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: festo-python-logging
|
|
3
|
-
Version: 0.0.
|
|
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
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
festo_python_logging/__init__.py,sha256=CaT3ujvoE8v0AVBSbF5QI_fKVqyCUI2QxCwEXHedCvg,1971
|
|
2
|
+
festo_python_logging/formatter.py,sha256=_g7niLa281GtukgAKPsZYV2o-0vrhstFDMZfpsC-lmE,1746
|
|
3
|
+
festo_python_logging/test.py,sha256=x8bpGVT0rz9En2Ic5DSRE3jL2R7U2YpfiSNbP25Tt_8,622
|
|
4
|
+
festo_python_logging-0.0.10.dist-info/METADATA,sha256=0vQNM0Bx2nxULlsWz_4nZW5MI-02EpQ6tQCkybeAu48,653
|
|
5
|
+
festo_python_logging-0.0.10.dist-info/WHEEL,sha256=kJCRJT_g0adfAJzTx2GUMmS80rTJIVHRCfG0DQgLq3o,88
|
|
6
|
+
festo_python_logging-0.0.10.dist-info/RECORD,,
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
festo_python_logging/__init__.py,sha256=Iw6ExyW2u3vO2kIkKBXs353ncZm6oDf4QOaLVXlYTBE,2030
|
|
2
|
-
festo_python_logging-0.0.7.dist-info/METADATA,sha256=ilO6tZN45XQV2ESeLOYu-aMOGWD0KhfALjuKMZiOafc,601
|
|
3
|
-
festo_python_logging-0.0.7.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
4
|
-
festo_python_logging-0.0.7.dist-info/RECORD,,
|