From 999537191656a63c548523c2f4d2223f78d2c67b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Wed, 5 Apr 2023 16:23:46 +0200 Subject: [PATCH] chg: Normalize logging on the config file settings --- bin/archiver.py | 4 ++-- bin/async_capture.py | 2 +- bin/background_indexer.py | 4 +++- bin/background_processing.py | 4 ++-- bin/start_website.py | 4 +++- lookyloo/default/abstractmanager.py | 8 ++++---- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/bin/archiver.py b/bin/archiver.py index 1a733c42..4cf23460 100755 --- a/bin/archiver.py +++ b/bin/archiver.py @@ -10,7 +10,7 @@ from collections import defaultdict from collections.abc import Mapping from datetime import datetime, timedelta from pathlib import Path -from typing import Dict, List +from typing import Dict, List, Optional from redis import Redis @@ -22,7 +22,7 @@ logging.config.dictConfig(get_config('logging')) class Archiver(AbstractManager): - def __init__(self, loglevel: int=logging.INFO): + def __init__(self, loglevel: Optional[int]=None): super().__init__(loglevel) self.script_name = 'archiver' self.redis = Redis(unix_socket_path=get_socket_path('cache')) diff --git a/bin/async_capture.py b/bin/async_capture.py index f2df0d6b..971a2193 100755 --- a/bin/async_capture.py +++ b/bin/async_capture.py @@ -23,7 +23,7 @@ logging.config.dictConfig(get_config('logging')) class AsyncCapture(AbstractManager): - def __init__(self, loglevel: int=logging.INFO): + def __init__(self, loglevel: Optional[int]=None): super().__init__(loglevel) self.script_name = 'async_capture' self.only_global_lookups: bool = get_config('generic', 'only_global_lookups') diff --git a/bin/background_indexer.py b/bin/background_indexer.py index 0db91315..a72f9075 100755 --- a/bin/background_indexer.py +++ b/bin/background_indexer.py @@ -5,6 +5,8 @@ import logging.config import os import shutil +from typing import Optional + from lookyloo.default import AbstractManager, get_config from lookyloo.exceptions import MissingUUID, NoValidHarFile from lookyloo.lookyloo import Lookyloo @@ -16,7 +18,7 @@ logging.config.dictConfig(get_config('logging')) class BackgroundIndexer(AbstractManager): - def __init__(self, loglevel: int=logging.INFO): + def __init__(self, loglevel: Optional[int]=None): super().__init__(loglevel) self.lookyloo = Lookyloo() self.script_name = 'background_indexer' diff --git a/bin/background_processing.py b/bin/background_processing.py index 7ea15e07..0566e543 100755 --- a/bin/background_processing.py +++ b/bin/background_processing.py @@ -5,7 +5,7 @@ import logging import logging.config from collections import Counter from datetime import date, timedelta -from typing import Any, Dict +from typing import Any, Dict, Optional from lookyloo.lookyloo import Lookyloo from lookyloo.default import AbstractManager, get_config, get_homedir, safe_create_dir @@ -16,7 +16,7 @@ logging.config.dictConfig(get_config('logging')) class Processing(AbstractManager): - def __init__(self, loglevel: int=logging.INFO): + def __init__(self, loglevel: Optional[int]=None): super().__init__(loglevel) self.script_name = 'processing' self.lookyloo = Lookyloo() diff --git a/bin/start_website.py b/bin/start_website.py index 4aa4d409..496bedc7 100755 --- a/bin/start_website.py +++ b/bin/start_website.py @@ -2,7 +2,9 @@ import logging import logging.config + from subprocess import Popen +from typing import Optional from lookyloo.default import get_config, get_homedir, AbstractManager @@ -11,7 +13,7 @@ logging.config.dictConfig(get_config('logging')) class Website(AbstractManager): - def __init__(self, loglevel: int=logging.INFO): + def __init__(self, loglevel: Optional[int]=None): super().__init__(loglevel) self.script_name = 'website' self.process = self._launch_website() diff --git a/lookyloo/default/abstractmanager.py b/lookyloo/default/abstractmanager.py index 75fe3279..4fcf916f 100644 --- a/lookyloo/default/abstractmanager.py +++ b/lookyloo/default/abstractmanager.py @@ -13,17 +13,17 @@ from typing import List, Optional, Tuple from redis import Redis from redis.exceptions import ConnectionError as RedisConnectionError -from .helpers import get_socket_path +from .helpers import get_socket_path, get_config class AbstractManager(ABC): script_name: str - def __init__(self, loglevel: int=logging.DEBUG): - self.loglevel = loglevel + def __init__(self, loglevel: Optional[int]=None): + self.loglevel: int = loglevel if loglevel is not None else get_config('generic', 'loglevel') or logging.INFO self.logger = logging.getLogger(f'{self.__class__.__name__}') - self.logger.setLevel(loglevel) + self.logger.setLevel(self.loglevel) self.logger.info(f'Initializing {self.__class__.__name__}') self.process: Optional[Popen] = None self.__redis = Redis(unix_socket_path=get_socket_path('cache'), db=1, decode_responses=True)