Skip to content

Commit 9ed4512

Browse files
committed
logging changes
Signed-off-by: Miguel Brandão <[email protected]>
1 parent cd2b108 commit 9ed4512

File tree

6 files changed

+8
-24
lines changed

6 files changed

+8
-24
lines changed

deepsearch/cli.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77

88
def setup_logger():
99
# Setting up root logger
10-
active_profile_settings = settings_mgr.get_profile_settings(
11-
settings_mgr.get_active_profile()
12-
)
10+
log_target_file, log_to_console = settings_mgr.get_logging_conf()
1311

14-
p = Path(active_profile_settings.log_target_file)
12+
p = Path(log_target_file)
1513
if not p.parent.is_dir():
1614
p.parent.mkdir(parents=True)
1715

@@ -20,7 +18,7 @@ def setup_logger():
2018
handlers: List[logging.Handler] = [
2119
logging.FileHandler(p),
2220
]
23-
if active_profile_settings.log_to_console:
21+
if log_to_console:
2422
handlers.append(logging.StreamHandler())
2523
formatter = logging.Formatter(
2624
"%(asctime)s %(name)s — %(levelname)s — %(module)s:%(funcName)s:%(lineno)d — %(message)s"

deepsearch/core/cli/profile.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ def add_profile(
3030
username: str = typer.Option(prompt=True),
3131
api_key: str = typer.Option(prompt=True, hide_input=True),
3232
verify_ssl: bool = typer.Option(default=True),
33-
log_directory: str = typer.Option(
34-
prompt=True, default=platformdirs.user_log_dir("DeepSearch", "IBM")
35-
),
36-
log_to_console: bool = typer.Option(default=False),
3733
profile_name: str = typer.Option(
3834
default="",
3935
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(
4945
username=username,
5046
api_key=api_key,
5147
verify_ssl=verify_ssl,
52-
log_target_file=log_directory,
53-
log_to_console=log_to_console,
5448
)
5549

5650
settings_mgr.save_settings(

deepsearch/core/client/config.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ class DeepSearchKeyAuth(BaseModel):
1616
DeepSearchAuth = Union[DeepSearchBearerTokenAuth, DeepSearchKeyAuth]
1717

1818

19-
class DeepSearchLogConfig(BaseModel):
20-
target_file: str = user_log_dir("DeepSearch", "IBM")
21-
write_to_console: bool = False
22-
23-
2419
class DeepSearchConfig(BaseModel):
2520
host: str
2621
auth: DeepSearchAuth
2722
verify_ssl: bool = True
28-
log_configuration: DeepSearchLogConfig

deepsearch/core/client/settings.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ class ProfileSettings(DumpableSettings):
3939
username: str
4040
api_key: SecretStr
4141
verify_ssl: bool = True
42-
log_target_file: str
43-
log_to_console: bool
4442

4543
class Config:
4644
env_prefix = "DEEPSEARCH_"
@@ -52,15 +50,15 @@ def from_cli_prompt(cls) -> ProfileSettings:
5250
username=input("Username: "),
5351
api_key=getpass("API key: "),
5452
verify_ssl=input("SSL verification [y/n]: "),
55-
log_directory=input("Log directory: "),
56-
log_to_console=input("log_to_console [y/n]: "),
5753
)
5854

5955

6056
class MainSettings(DumpableSettings):
6157

6258
profile: Optional[str] = None # None only when profiles not yet iniitialized
6359
show_cli_stack_traces: bool = False
60+
log_file: str = platformdirs.user_log_dir("DeepSearch", "IBM")
61+
log_to_console: bool = False
6462

6563
class Config:
6664
env_prefix = "DEEPSEARCH_"

deepsearch/core/client/settings_manager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ def _migrate_legacy_config(self) -> None:
8686
username=legacy_cfg.auth.username,
8787
api_key=legacy_cfg.auth.api_key,
8888
verify_ssl=legacy_cfg.verify_ssl,
89-
log_directory=platformdirs.user_log_dir("DeepSearch", "IBM"),
90-
log_to_console=False,
9189
)
9290
self.save_settings(
9391
profile_settgs=new_cfg,
@@ -99,6 +97,9 @@ def _migrate_legacy_config(self) -> None:
9997
def _get_profile_path(self, profile_name: str) -> Path:
10098
return self._profile_root_path / f"{profile_name}.env"
10199

100+
def get_logging_conf(self) -> tuple[str, bool]:
101+
return self._main_settings.log_file, self._main_settings.log_to_console
102+
102103
def get_all_profile_settings(self) -> Dict[str, ProfileSettings]:
103104
return {k: self._profile_cache[k].settings for k in self._profile_cache}
104105

deepsearch/cps/cli/main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22

33
logger = logging.getLogger("root.cps")
4-
print(logger.handlers)
54

65
import typer
76

0 commit comments

Comments
 (0)