festo-python-logging 0.0.4__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.
@@ -0,0 +1,62 @@
1
+ import logging
2
+ import sys
3
+ from datetime import datetime
4
+ from pathlib import Path
5
+ from typing import List, Optional
6
+
7
+
8
+ def configure_logging(
9
+ verbose: bool = False,
10
+ silence: Optional[List[str]] = None,
11
+ log_dir: Optional[str] = None,
12
+ ) -> None:
13
+ """Configures logging for the application.
14
+
15
+ Args:
16
+ verbose (bool): If True, sets the logging level to DEBUG.
17
+ silence (Optional[List[str]]): A list of logger names to silence by setting their level to ERROR.
18
+ log_dir (Optional[str]): Directory path where log files will be saved.
19
+ If None, logging to file is disabled.
20
+
21
+ Returns:
22
+ None
23
+
24
+ """
25
+ # 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
+ )
30
+ file_formatter = logging.Formatter(
31
+ fmt="{relativeCreated:13.2f} {levelname:>8} {name:>35.35}:{lineno:4d} │ {message}",
32
+ style="{",
33
+ )
34
+
35
+ # Set up the stdout handler
36
+ stdout_handler = logging.StreamHandler(sys.stdout)
37
+ stdout_handler.setFormatter(stdout_formatter)
38
+
39
+ # Create the handlers list and add the stdout handler
40
+ handlers = [stdout_handler]
41
+
42
+ # If a log file path is provided, set up the file handler
43
+ if log_dir:
44
+ log_dir = Path(log_dir)
45
+ log_dir.mkdir(parents=True, exist_ok=True)
46
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
47
+ file_handler = logging.FileHandler(log_dir / f"log_{timestamp}.log")
48
+ file_handler.setFormatter(file_formatter)
49
+ handlers.append(file_handler)
50
+
51
+ # Configure the basic logging setup
52
+ level = logging.DEBUG if verbose else logging.INFO
53
+ logging.basicConfig(level=level, handlers=handlers)
54
+ logging.info("Logging configured")
55
+
56
+ # Silence specified loggers if requested
57
+ if silence:
58
+ for logger_name in silence:
59
+ logging.getLogger(logger_name).setLevel(logging.ERROR)
60
+
61
+
62
+ __all__ = ["configure_logging"]
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.3
2
+ Name: festo-python-logging
3
+ Version: 0.0.4
4
+ Summary: Convenience function to configure python logging.
5
+ License: Proprietary
6
+ Author: Charles Wilmot
7
+ Author-email: charles.wilmot@festo.com
8
+ Maintainer: Charles Wilmot
9
+ Maintainer-email: charles.wilmot@festo.com
10
+ Requires-Python: >=3.10
11
+ Classifier: License :: Other/Proprietary License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
@@ -0,0 +1,4 @@
1
+ festo_python_logging/__init__.py,sha256=Iw6ExyW2u3vO2kIkKBXs353ncZm6oDf4QOaLVXlYTBE,2030
2
+ festo_python_logging-0.0.4.dist-info/METADATA,sha256=-Sh3wfY4zGPb5jhvXON9OYr10pfkK6gzOmdkUzvF3wg,601
3
+ festo_python_logging-0.0.4.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
4
+ festo_python_logging-0.0.4.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.1.3
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any