festo-python-logging 0.0.4__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.
@@ -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,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,96 @@
1
+ [build-system]
2
+ requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
3
+ build-backend = "poetry_dynamic_versioning.backend"
4
+
5
+
6
+ [tool.poetry]
7
+ name = "festo-python-logging"
8
+ version = "0.0.4"
9
+ license = "Proprietary"
10
+ authors = [
11
+ "Charles Wilmot <charles.wilmot@festo.com>",
12
+ ]
13
+ maintainers = [
14
+ "Charles Wilmot <charles.wilmot@festo.com>",
15
+ ]
16
+ description = "Convenience function to configure python logging."
17
+
18
+
19
+
20
+ [tool.poetry.requires-plugins]
21
+ poetry-dynamic-versioning = { version = ">=1.0.0,<2.0.0", extras = ["plugin"] }
22
+
23
+
24
+
25
+ [tool.poetry-dynamic-versioning]
26
+ enable = false
27
+
28
+
29
+
30
+ [tool.poetry.dependencies]
31
+ python = ">=3.10"
32
+
33
+
34
+
35
+ [tool.poetry.group.dev]
36
+ optional = true
37
+ [tool.poetry.group.dev.dependencies]
38
+ ruff="*"
39
+ pytest="*"
40
+
41
+
42
+
43
+ [tool.ruff]
44
+ line-length = 120
45
+ fix = true
46
+
47
+
48
+
49
+ [tool.ruff.lint]
50
+ select = ["E", "F", "B", "D", "I", "PT", "NPY", "COM"]
51
+ ignore = [
52
+ "C901", # mccabe complexity
53
+ "PT003", # pytest-extraneous-scope-function - on some functions we make this intentionally explicit for
54
+ # clarity purposess
55
+ "F821", # disabled pending better integration for omni packages
56
+ "ANN401", # at the moment a lot of these annotations are necessary due to missing upstream typing support,
57
+ "D100", # not enforced pending decision on documentation requirements
58
+ "D104", # not enforced pending decision on documentation requirements
59
+ "D401", # Do not enforce first word being in impertative
60
+ "D211",
61
+ "D213",
62
+ "TRY003", # raise-vanilla-args
63
+ "PLR0913", # too-many-function-args
64
+ "PLC1901", # compare-to-empty string
65
+ "TRY300", #
66
+
67
+ "D105", # undocumented-magic-method
68
+ "RET505", # superfluous-else-return
69
+ "RET506", # superfluous-else-raise
70
+ "RET507", # superfluous-else-continue
71
+ "RET508", # superfluous-else-break
72
+ ]
73
+
74
+
75
+
76
+ [tool.ruff.format]
77
+ skip-magic-trailing-comma = false
78
+ docstring-code-format = false
79
+ docstring-code-line-length = "dynamic"
80
+
81
+
82
+
83
+ [tool.ruff.lint.per-file-ignores]
84
+ "tests/*" = [
85
+ "S101",
86
+ "D",
87
+ "PT018",
88
+ "SIM223", # both to support assert False and "Infotext" assertions for assert clarity
89
+ "ANN201", # missing-return-type-undocumented-public-function
90
+ "SLF001", # private-member-access
91
+ "ANN202", # missing-return-type-private-function
92
+ "PLR2004", # magic-value-comparison
93
+ ]
94
+ "setup.py" = ["ALL"]
95
+ # temporarily excludes conftest.py file from linting due to autofix incompatibilities
96
+ "conftest.py" = ["ALL"]