Skip to content

Commit

Permalink
Add logging facility.
Browse files Browse the repository at this point in the history
Signed-off-by: Giacomo Leidi <[email protected]>
  • Loading branch information
gleidi-suse committed Mar 29, 2024
1 parent 0dd6696 commit 6d9b28f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from textual.app import App
from textual.command import Provider, Hits, Hit

from pot.config import get_config, CONTAINERS_MODE, IMAGES_MODE, VOLUMES_MODE
from pot.config import init_logging, get_config, CONTAINERS_MODE, IMAGES_MODE, VOLUMES_MODE
from pot.ui.container import ContainersScreen
from pot.ui.image import ImagesScreen
from pot.ui.volume import VolumesScreen
Expand Down Expand Up @@ -54,6 +54,7 @@ def on_mount(self) -> None:


def main():
init_logging()
app = PotApp()
app.run()

Expand Down
34 changes: 32 additions & 2 deletions pot/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging
from logging.config import dictConfig
from pathlib import Path

import toml
Expand All @@ -6,6 +8,8 @@

from pot.utils import get_version

logger = logging.getLogger(__name__)

CONTAINERS_MODE = "containers"
IMAGES_MODE = "images"
VOLUMES_MODE = "volumes"
Expand All @@ -18,7 +22,25 @@

DEFAULT_CONFIG = {
"oci": {"runtime": "docker"},
"ui": {"refresh_timeout": 10, "startup_mode": "containers"}
"ui": {"refresh_timeout": 10, "startup_mode": "containers"},
"logging": {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"standard": {
"format": "[%(asctime)s] [%(levelno)s] [%(levelname)s] %(message)s"
}
},
"handlers": {
"console": {
"level": "INFO",
"class": "logging.StreamHandler",
"formatter": "standard",
"stream": "ext://sys.stdout"
}
},
"root": {"level": "INFO", "handlers": ["console"]}
}
}


Expand Down Expand Up @@ -66,7 +88,10 @@ def merge_configs(first: dict, second: dict) -> dict:

for k, v in merged.items():
if type(v) is dict:
merged[k] = merge_configs(first[k], second[k])
if k not in second:
merged[k] = first[k]
else:
merged[k] = merge_configs(first[k], second[k])

return merged

Expand All @@ -92,3 +117,8 @@ def get_config() -> dict:
return merge_configs(DEFAULT_CONFIG, valid_config)
else:
return DEFAULT_CONFIG


def init_logging():
config = get_config()
dictConfig(config["logging"])

0 comments on commit 6d9b28f

Please sign in to comment.