From 9ed4512ef5f04f07bfca17a666fa8f0a88773cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Brand=C3=A3o?= <555migalves555@gmail.com> Date: Thu, 27 Jul 2023 10:50:37 +0100 Subject: [PATCH] logging changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miguel Brandão <555migalves555@gmail.com> --- deepsearch/cli.py | 8 +++----- deepsearch/core/cli/profile.py | 6 ------ deepsearch/core/client/config.py | 6 ------ deepsearch/core/client/settings.py | 6 ++---- deepsearch/core/client/settings_manager.py | 5 +++-- deepsearch/cps/cli/main.py | 1 - 6 files changed, 8 insertions(+), 24 deletions(-) diff --git a/deepsearch/cli.py b/deepsearch/cli.py index 8bdd3974..4e9243aa 100644 --- a/deepsearch/cli.py +++ b/deepsearch/cli.py @@ -7,11 +7,9 @@ def setup_logger(): # Setting up root logger - active_profile_settings = settings_mgr.get_profile_settings( - settings_mgr.get_active_profile() - ) + log_target_file, log_to_console = settings_mgr.get_logging_conf() - p = Path(active_profile_settings.log_target_file) + p = Path(log_target_file) if not p.parent.is_dir(): p.parent.mkdir(parents=True) @@ -20,7 +18,7 @@ def setup_logger(): handlers: List[logging.Handler] = [ logging.FileHandler(p), ] - if active_profile_settings.log_to_console: + if log_to_console: handlers.append(logging.StreamHandler()) formatter = logging.Formatter( "%(asctime)s %(name)s — %(levelname)s — %(module)s:%(funcName)s:%(lineno)d — %(message)s" diff --git a/deepsearch/core/cli/profile.py b/deepsearch/core/cli/profile.py index 56fafb44..ebe77621 100644 --- a/deepsearch/core/cli/profile.py +++ b/deepsearch/core/cli/profile.py @@ -30,10 +30,6 @@ def add_profile( username: str = typer.Option(prompt=True), api_key: str = typer.Option(prompt=True, hide_input=True), verify_ssl: bool = typer.Option(default=True), - log_directory: str = typer.Option( - prompt=True, default=platformdirs.user_log_dir("DeepSearch", "IBM") - ), - log_to_console: bool = typer.Option(default=False), profile_name: str = typer.Option( default="", help="If not set, the active profile will be updated or, if no profile available, a new profile with a predetermined name will be created.", @@ -49,8 +45,6 @@ def add_profile( username=username, api_key=api_key, verify_ssl=verify_ssl, - log_target_file=log_directory, - log_to_console=log_to_console, ) settings_mgr.save_settings( diff --git a/deepsearch/core/client/config.py b/deepsearch/core/client/config.py index 314ab5dc..cc7e8d5b 100644 --- a/deepsearch/core/client/config.py +++ b/deepsearch/core/client/config.py @@ -16,13 +16,7 @@ class DeepSearchKeyAuth(BaseModel): DeepSearchAuth = Union[DeepSearchBearerTokenAuth, DeepSearchKeyAuth] -class DeepSearchLogConfig(BaseModel): - target_file: str = user_log_dir("DeepSearch", "IBM") - write_to_console: bool = False - - class DeepSearchConfig(BaseModel): host: str auth: DeepSearchAuth verify_ssl: bool = True - log_configuration: DeepSearchLogConfig diff --git a/deepsearch/core/client/settings.py b/deepsearch/core/client/settings.py index 9561938f..249d1aa1 100644 --- a/deepsearch/core/client/settings.py +++ b/deepsearch/core/client/settings.py @@ -39,8 +39,6 @@ class ProfileSettings(DumpableSettings): username: str api_key: SecretStr verify_ssl: bool = True - log_target_file: str - log_to_console: bool class Config: env_prefix = "DEEPSEARCH_" @@ -52,8 +50,6 @@ def from_cli_prompt(cls) -> ProfileSettings: username=input("Username: "), api_key=getpass("API key: "), verify_ssl=input("SSL verification [y/n]: "), - log_directory=input("Log directory: "), - log_to_console=input("log_to_console [y/n]: "), ) @@ -61,6 +57,8 @@ class MainSettings(DumpableSettings): profile: Optional[str] = None # None only when profiles not yet iniitialized show_cli_stack_traces: bool = False + log_file: str = platformdirs.user_log_dir("DeepSearch", "IBM") + log_to_console: bool = False class Config: env_prefix = "DEEPSEARCH_" diff --git a/deepsearch/core/client/settings_manager.py b/deepsearch/core/client/settings_manager.py index 791fdee1..bb6fcb89 100644 --- a/deepsearch/core/client/settings_manager.py +++ b/deepsearch/core/client/settings_manager.py @@ -86,8 +86,6 @@ def _migrate_legacy_config(self) -> None: username=legacy_cfg.auth.username, api_key=legacy_cfg.auth.api_key, verify_ssl=legacy_cfg.verify_ssl, - log_directory=platformdirs.user_log_dir("DeepSearch", "IBM"), - log_to_console=False, ) self.save_settings( profile_settgs=new_cfg, @@ -99,6 +97,9 @@ def _migrate_legacy_config(self) -> None: def _get_profile_path(self, profile_name: str) -> Path: return self._profile_root_path / f"{profile_name}.env" + def get_logging_conf(self) -> tuple[str, bool]: + return self._main_settings.log_file, self._main_settings.log_to_console + def get_all_profile_settings(self) -> Dict[str, ProfileSettings]: return {k: self._profile_cache[k].settings for k in self._profile_cache} diff --git a/deepsearch/cps/cli/main.py b/deepsearch/cps/cli/main.py index ed22b74f..d557f9bc 100644 --- a/deepsearch/cps/cli/main.py +++ b/deepsearch/cps/cli/main.py @@ -1,7 +1,6 @@ import logging logger = logging.getLogger("root.cps") -print(logger.handlers) import typer