Settings.log group

This commit is contained in:
Jörn-Michael Miehe 2023-08-31 23:29:27 +00:00
parent c5a3cac61e
commit 57da462dd7
3 changed files with 12 additions and 7 deletions

2
.vscode/launch.json vendored
View file

@ -11,7 +11,7 @@
"module": "kiwi_simple_metrics.main", "module": "kiwi_simple_metrics.main",
"env": { "env": {
"METRIC__INTERVAL": "5", "METRIC__INTERVAL": "5",
"METRIC__QUIET": "False", "METRIC__LOG__ENABLED": "True",
"METRIC__DISK__PATHS": "[\"/var\", \"/\", \"/dev\"]", "METRIC__DISK__PATHS": "[\"/var\", \"/\", \"/dev\"]",
}, },
"justMyCode": true "justMyCode": true

View file

@ -16,7 +16,7 @@ async def run_metrics() -> None:
metrics.disk(), metrics.disk(),
) )
if not SETTINGS.quiet: if SETTINGS.log.enabled:
print(report) print(report)
await interval await interval

View file

@ -82,6 +82,14 @@ class DiskMS(MetricSettings):
paths: list[DirectoryPath] = Field(default_factory=list) 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): class Settings(BaseSettings):
model_config = SettingsConfigDict( model_config = SettingsConfigDict(
env_prefix="METRIC__", env_prefix="METRIC__",
@ -91,11 +99,8 @@ class Settings(BaseSettings):
# time between gathering reports # time between gathering reports
interval: float = 600 interval: float = 600
# if False, prints reports to stdout # reporting to stdout
quiet: bool = True log: LogSettings = LogSettings()
# how to format reports to stdout
report_stdout: str = "[{state}] {result}"
# separates metrics and values in reports # separates metrics and values in reports
separator: str = ", " separator: str = ", "