From 098d6debafb332759438e56677a8136ed2ff6e89 Mon Sep 17 00:00:00 2001 From: Alberto Soutullo Date: Wed, 13 Mar 2024 18:31:18 +0100 Subject: [PATCH] Fixed logger to avoid logging external libraries --- main.py | 12 +++++++++--- src/__init__.py | 0 src/logger/logger.py | 3 +-- src/logger/logger_config.yaml | 23 +++++++++++------------ src/plotting/plotter.py | 4 ++-- 5 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 src/__init__.py diff --git a/main.py b/main.py index c5f3771..5b6de2b 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,10 @@ # Python Imports -import src.logger.logger from kubernetes import client, config # Project Imports +import src.logger.logger +from src.utils import file_utils +from src.plotting.plotter import Plotter from src.metrics.scrapper import Scrapper @@ -13,8 +15,12 @@ def main(): v1 = client.CoreV1Api() - scrapper = Scrapper(url, scrape_config, "test/") - scrapper.query_and_dump_metrics() + # scrapper = Scrapper(url, scrape_config, "test/") + # scrapper.query_and_dump_metrics() + + config_dict = file_utils.read_yaml_file("scrape.yaml") + plotter = Plotter(config_dict["plotting"]) + plotter.create_plots() if __name__ == '__main__': diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/logger/logger.py b/src/logger/logger.py index b172122..927bc81 100644 --- a/src/logger/logger.py +++ b/src/logger/logger.py @@ -1,8 +1,7 @@ import logging.config import yaml + with open('src/logger/logger_config.yaml', 'r') as f: config = yaml.safe_load(f.read()) logging.config.dictConfig(config) - -log = logging.getLogger(__name__) diff --git a/src/logger/logger_config.yaml b/src/logger/logger_config.yaml index 66057d1..e050594 100644 --- a/src/logger/logger_config.yaml +++ b/src/logger/logger_config.yaml @@ -1,18 +1,17 @@ version: 1 +disable_existing_loggers: True formatters: simple: format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s' handlers: - console: - class: logging.StreamHandler - level: DEBUG - formatter: simple - stream: ext://sys.stdout + console_handler: + level: "DEBUG" + formatter: "simple" + class: "logging.StreamHandler" + stream: "ext://sys.stdout" loggers: - sampleLogger: - level: DEBUG - handlers: [console] - propagate: no -root: - level: DEBUG - handlers: [console] \ No newline at end of file + src: + level: "DEBUG" + handlers: + - "console_handler" + propagate: False \ No newline at end of file diff --git a/src/plotting/plotter.py b/src/plotting/plotter.py index 06435ee..d6bdf15 100644 --- a/src/plotting/plotter.py +++ b/src/plotting/plotter.py @@ -10,7 +10,7 @@ from typing import List, Dict from matplotlib import ticker # Project Imports -from utils.file_utils import get_files_from_folder_path, get_file_name_from_path +from src.utils.file_utils import get_files_from_folder_path, get_file_name_from_path logger = logging.getLogger(__name__) sns.set_theme() @@ -22,6 +22,7 @@ class Plotter: def create_plots(self): for plot_name, plot_specs in self._config.items(): + logger.debug(f"Plotting \"{plot_name}\"") self._create_plot(plot_name, plot_specs) def _create_plot(self, plot_name: str, plot_specs: Dict): @@ -89,7 +90,6 @@ class Plotter: def _create_subplot_paths_group(self, plot_specs: Dict) -> List: subplot_path = [ ([f"{folder}{data}" for folder in plot_specs["folder"]], data) for data in plot_specs["data"] - ] return subplot_path