rats-apps 0.10.3.dev20250519235742__py3-none-any.whl → 0.10.3.dev20250520164722__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.
- rats/logs/__init__.py +17 -2
- rats/logs/_app.py +55 -4
- {rats_apps-0.10.3.dev20250519235742.dist-info → rats_apps-0.10.3.dev20250520164722.dist-info}/METADATA +1 -1
- {rats_apps-0.10.3.dev20250519235742.dist-info → rats_apps-0.10.3.dev20250520164722.dist-info}/RECORD +5 -5
- {rats_apps-0.10.3.dev20250519235742.dist-info → rats_apps-0.10.3.dev20250520164722.dist-info}/WHEEL +0 -0
rats/logs/__init__.py
CHANGED
@@ -1,7 +1,22 @@
|
|
1
|
-
"""
|
1
|
+
"""
|
2
|
+
Small module to help configure logging for rats applications.
|
2
3
|
|
3
|
-
|
4
|
+
We provide a rats application that can be executed at the beginning of your process, that will
|
5
|
+
handle configuring the python logging libraries, with a few configuration options being exposed.
|
6
|
+
|
7
|
+
!!! warning
|
8
|
+
We expose the logging functionality through a [rats.apps.AppContainer][] in order to leverage
|
9
|
+
the built in plugin system to give users the ability to adjust the default settings, but this
|
10
|
+
entire application should be lightweight and should not contain very complex logic, avoiding
|
11
|
+
logic that is very time consuming or has a chance of failing with confusing errors.
|
12
|
+
|
13
|
+
If the logging options made available through this module are far from what is desired, instead
|
14
|
+
of adding flags and options to this module, we recommend configuring logging in your own code.
|
15
|
+
"""
|
16
|
+
|
17
|
+
from ._app import AppConfigs, ConfigureApplication
|
4
18
|
|
5
19
|
__all__ = [
|
20
|
+
"AppConfigs",
|
6
21
|
"ConfigureApplication",
|
7
22
|
]
|
rats/logs/_app.py
CHANGED
@@ -1,12 +1,58 @@
|
|
1
1
|
import logging.config
|
2
|
+
import warnings
|
3
|
+
from collections.abc import Iterator
|
4
|
+
from typing import Any
|
2
5
|
|
3
6
|
from rats import apps
|
4
7
|
|
5
8
|
logger = logging.getLogger(__name__)
|
9
|
+
LoggerConfigEntry = tuple[str, dict[str, Any]]
|
10
|
+
|
11
|
+
|
12
|
+
@apps.autoscope
|
13
|
+
class AppConfigs:
|
14
|
+
LOGGERS = apps.ServiceId[LoggerConfigEntry]("loggers.config-group")
|
15
|
+
"""
|
16
|
+
Register additional loggers to this service group.
|
17
|
+
|
18
|
+
```python
|
19
|
+
from rats import apps
|
20
|
+
|
21
|
+
|
22
|
+
class PluginContainer(apps.Container, apps.PluginMixin):
|
23
|
+
@apps.group(AppConfigs.LOGGERS)
|
24
|
+
def _custom_loggers(self) -> Iterator[LoggerConfigEntry]:
|
25
|
+
yield "", {"level": "INFO", "handlers": ["console"]}
|
26
|
+
yield "azure", {"level": "WARNING", "handlers": ["console"]}
|
27
|
+
|
28
|
+
|
29
|
+
# provide the new configuration when executing `logs.ConfigureAppilcation`
|
30
|
+
apps.run(apps.AppBundle(
|
31
|
+
app_plugin=logs.ConfigureApplication,
|
32
|
+
container_plugin=PluginContainer,
|
33
|
+
))
|
34
|
+
```
|
35
|
+
"""
|
6
36
|
|
7
37
|
|
8
38
|
class ConfigureApplication(apps.AppContainer, apps.PluginMixin):
|
39
|
+
"""
|
40
|
+
Configure logging for the current process.
|
41
|
+
|
42
|
+
We try to provide some simple default loggers, but you can replace the loggers by providing the
|
43
|
+
[rats.logs.AppConfigs.LOGGERS][] service group.
|
44
|
+
|
45
|
+
```python
|
46
|
+
from rats import apps, logs
|
47
|
+
|
48
|
+
apps.run(apps.AppBundle(app_plugin=logs.ConfigureApplication))
|
49
|
+
```
|
50
|
+
"""
|
51
|
+
|
9
52
|
def execute(self) -> None:
|
53
|
+
"""Applies the logging configuration."""
|
54
|
+
logger_configs = self._app.get_group(AppConfigs.LOGGERS)
|
55
|
+
loggers_dict = {key: value for key, value in logger_configs}
|
10
56
|
logging.config.dictConfig(
|
11
57
|
{
|
12
58
|
"version": 1,
|
@@ -36,10 +82,15 @@ class ConfigureApplication(apps.AppContainer, apps.PluginMixin):
|
|
36
82
|
"stream": "ext://sys.stderr",
|
37
83
|
}
|
38
84
|
},
|
39
|
-
"loggers":
|
40
|
-
"": {"level": "INFO", "handlers": ["console"]},
|
41
|
-
"azure": {"level": "WARNING", "handlers": ["console"]},
|
42
|
-
},
|
85
|
+
"loggers": loggers_dict,
|
43
86
|
}
|
44
87
|
)
|
88
|
+
# enable deprecation warnings by default
|
89
|
+
logging.captureWarnings(True)
|
90
|
+
warnings.simplefilter("default", DeprecationWarning)
|
45
91
|
logger.debug("done configuring logging")
|
92
|
+
|
93
|
+
@apps.fallback_group(AppConfigs.LOGGERS)
|
94
|
+
def _default_loggers(self) -> Iterator[LoggerConfigEntry]:
|
95
|
+
yield "", {"level": "INFO", "handlers": ["console"]}
|
96
|
+
yield "azure", {"level": "WARNING", "handlers": ["console"]}
|
{rats_apps-0.10.3.dev20250519235742.dist-info → rats_apps-0.10.3.dev20250520164722.dist-info}/RECORD
RENAMED
@@ -30,8 +30,8 @@ rats/cli/_container.py,sha256=FIQBqi9PTNpE2P52qkfGET51BczdD-JvcWXLTjCNPDI,3512
|
|
30
30
|
rats/cli/_functions.py,sha256=BNmgWVquQUEqJAYsed_l8vLnlLP7u3XC1TDyEFI1AiU,1552
|
31
31
|
rats/cli/_plugin.py,sha256=o-pmEqU6mVH3QoRfRBrbG-XRTWCzt6pLKtSV3-5VSx0,1144
|
32
32
|
rats/cli/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
33
|
-
rats/logs/__init__.py,sha256=
|
34
|
-
rats/logs/_app.py,sha256=
|
33
|
+
rats/logs/__init__.py,sha256=dSO-V2eu2W7w4w7oRau-UOfXXIkyZ2bHB6-kaasbeFM,970
|
34
|
+
rats/logs/_app.py,sha256=SoTxk6g84tygOP_346NwXPcG1o6KZLd7lIgayq5vMdc,3239
|
35
35
|
rats/logs/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
36
36
|
rats_e2e/apps/__init__.py,sha256=c2QG818ACyS9MBXs_Evg5yYT6k-KPMQfIqF7Z77Cau0,142
|
37
37
|
rats_e2e/apps/__main__.py,sha256=ETECGDD8glcbmx0P-WWmjQQX6gtF-5L7_DxZjNmx3X4,350
|
@@ -42,6 +42,6 @@ rats_e2e/apps/inputs/_app.py,sha256=FiaLgOZc-d1ryKSwKnL5XBNGcOP1bHbxxeMJqoU_RJg,
|
|
42
42
|
rats_e2e/apps/minimal/__init__.py,sha256=bUR6Oexx6Jsouxor0cL9emXoVha4cm3WqyhU1pgchsI,521
|
43
43
|
rats_e2e/apps/minimal/__main__.py,sha256=Mf-a2iQKTTgh9hMd6AeuzmU9araMIyf1AtdWkh_L07E,117
|
44
44
|
rats_e2e/apps/minimal/_app.py,sha256=CQ09LVTNRarz7Pb1wiSuNHrZ_2KGcgH8nUqy4BjxMUY,849
|
45
|
-
rats_apps-0.10.3.
|
46
|
-
rats_apps-0.10.3.
|
47
|
-
rats_apps-0.10.3.
|
45
|
+
rats_apps-0.10.3.dev20250520164722.dist-info/METADATA,sha256=bohmgF0FEaU8yt4eVjEvGPFkgZn3U1qc7k1qRpPSk0w,867
|
46
|
+
rats_apps-0.10.3.dev20250520164722.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
47
|
+
rats_apps-0.10.3.dev20250520164722.dist-info/RECORD,,
|
{rats_apps-0.10.3.dev20250519235742.dist-info → rats_apps-0.10.3.dev20250520164722.dist-info}/WHEEL
RENAMED
File without changes
|