From 57da462dd710ccdd0ad08d40d5d481d4a56df566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Thu, 31 Aug 2023 23:29:27 +0000 Subject: [PATCH] Settings.log group --- .vscode/launch.json | 2 +- kiwi_simple_metrics/main.py | 2 +- kiwi_simple_metrics/settings.py | 15 ++++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index cd3eae0..b77d253 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,7 @@ "module": "kiwi_simple_metrics.main", "env": { "METRIC__INTERVAL": "5", - "METRIC__QUIET": "False", + "METRIC__LOG__ENABLED": "True", "METRIC__DISK__PATHS": "[\"/var\", \"/\", \"/dev\"]", }, "justMyCode": true diff --git a/kiwi_simple_metrics/main.py b/kiwi_simple_metrics/main.py index a0fe787..06c0b59 100644 --- a/kiwi_simple_metrics/main.py +++ b/kiwi_simple_metrics/main.py @@ -16,7 +16,7 @@ async def run_metrics() -> None: metrics.disk(), ) - if not SETTINGS.quiet: + if SETTINGS.log.enabled: print(report) await interval diff --git a/kiwi_simple_metrics/settings.py b/kiwi_simple_metrics/settings.py index 49c2127..bb3fc1f 100644 --- a/kiwi_simple_metrics/settings.py +++ b/kiwi_simple_metrics/settings.py @@ -82,6 +82,14 @@ class DiskMS(MetricSettings): paths: list[DirectoryPath] = Field(default_factory=list) +class LogSettings(BaseModel): + # if True, prints reports to stdout + enabled: bool = False + + # how to format reports to stdout + format: str = "[{state}] {result}" + + class Settings(BaseSettings): model_config = SettingsConfigDict( env_prefix="METRIC__", @@ -91,11 +99,8 @@ class Settings(BaseSettings): # time between gathering reports interval: float = 600 - # if False, prints reports to stdout - quiet: bool = True - - # how to format reports to stdout - report_stdout: str = "[{state}] {result}" + # reporting to stdout + log: LogSettings = LogSettings() # separates metrics and values in reports separator: str = ", "