Fixed logger to avoid logging external libraries

This commit is contained in:
Alberto Soutullo 2024-03-13 18:31:18 +01:00
parent 42fc400c8d
commit 9afc94b28a
No known key found for this signature in database
GPG Key ID: A7CAC0D8343B0387
5 changed files with 23 additions and 19 deletions

12
main.py
View File

@ -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__':

0
src/__init__.py Normal file
View File

View File

@ -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__)

View File

@ -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]
src:
level: "DEBUG"
handlers:
- "console_handler"
propagate: False

View File

@ -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