Skip to content

Commit

Permalink
logging changes
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Brandão <[email protected]>
  • Loading branch information
HolyMichael committed Aug 7, 2023
1 parent cd2b108 commit 9ed4512
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 24 deletions.
8 changes: 3 additions & 5 deletions deepsearch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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"
Expand Down
6 changes: 0 additions & 6 deletions deepsearch/core/cli/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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(
Expand Down
6 changes: 0 additions & 6 deletions deepsearch/core/client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 deletions deepsearch/core/client/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_"
Expand All @@ -52,15 +50,15 @@ 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]: "),
)


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_"
5 changes: 3 additions & 2 deletions deepsearch/core/client/settings_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}

Expand Down
1 change: 0 additions & 1 deletion deepsearch/cps/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging

logger = logging.getLogger("root.cps")
print(logger.handlers)

import typer

Expand Down

0 comments on commit 9ed4512

Please sign in to comment.