summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrique Joaquim <henriquecjoaquim@gmail.com>2024-06-07 11:57:23 +0100
committerGitHub <noreply@github.com>2024-06-07 10:57:23 +0000
commitaa7bccc4eccc67764ecd3a62f1e7c5f8323cbac0 (patch)
tree28fd5be48d94ad7f16a23095b4384d88165ea6ea
parentd7a9e666b98a7456d8bcc01c1ae7d026a2a566b3 (diff)
[Feature] CLI logging (#6487)v4.2.2v4.2.1v4.2.0
* remove old logging references * cli as logging subapp option * changing the subapp to the cli on init
-rw-r--r--cli/openbb_cli/cli.py10
-rw-r--r--cli/openbb_cli/controllers/cli_controller.py12
-rw-r--r--cli/openbb_cli/utils/utils.py34
-rw-r--r--openbb_platform/core/openbb_core/app/model/system_settings.py2
4 files changed, 44 insertions, 14 deletions
diff --git a/cli/openbb_cli/cli.py b/cli/openbb_cli/cli.py
index 1937a05d37b..91c2b4825d8 100644
--- a/cli/openbb_cli/cli.py
+++ b/cli/openbb_cli/cli.py
@@ -2,6 +2,8 @@
import sys
+from openbb_cli.utils.utils import change_logging_sub_app, reset_logging_sub_app
+
def main():
"""Use the main entry point for the OpenBB Platform CLI."""
@@ -20,4 +22,10 @@ def main():
if __name__ == "__main__":
- main()
+ initial_logging_sub_app = change_logging_sub_app()
+ try:
+ main()
+ except Exception as e:
+ pass
+ finally:
+ reset_logging_sub_app(initial_logging_sub_app)
diff --git a/cli/openbb_cli/controllers/cli_controller.py b/cli/openbb_cli/controllers/cli_controller.py
index 31d32499659..807af177ce5 100644
--- a/cli/openbb_cli/controllers/cli_controller.py
+++ b/cli/openbb_cli/controllers/cli_controller.py
@@ -4,7 +4,6 @@
import argparse
import contextlib
import difflib
-import logging
import os
import re
import sys
@@ -60,8 +59,6 @@ DATA_PROCESSING_ROUTERS = ["technical", "quantitative", "econometrics"]
# pylint: disable=too-many-public-methods,import-outside-toplevel, too-many-function-args
# pylint: disable=too-many-branches,no-member,C0302,too-many-return-statements, inconsistent-return-statements
-logger = logging.getLogger(__name__)
-
env_file = str(ENV_FILE_SETTINGS)
session = Session()
@@ -498,11 +495,6 @@ class CLIController(BaseController):
def handle_job_cmds(jobs_cmds: Optional[List[str]]) -> Optional[List[str]]:
"""Handle job commands."""
- # If the path selected does not start from the user root,
- # give relative location from root
- if jobs_cmds is not None and jobs_cmds:
- logger.info("INPUT: %s", "/".join(jobs_cmds))
-
export_path = ""
if jobs_cmds and "export" in jobs_cmds[0]:
commands = jobs_cmds[0].split("/")
@@ -620,10 +612,6 @@ def run_cli(jobs_cmds: Optional[List[str]] = None, test_mode=False):
break
except SystemExit:
- logger.exception(
- "The command '%s' doesn't exist on the / menu.",
- an_input,
- )
session.console.print(
f"[red]The command '{an_input}' doesn't exist on the / menu.[/red]\n",
)
diff --git a/cli/openbb_cli/utils/utils.py b/cli/openbb_cli/utils/utils.py
new file mode 100644
index 00000000000..b38c83a8dab
--- /dev/null
+++ b/cli/openbb_cli/utils/utils.py
@@ -0,0 +1,34 @@
+"""OpenBB Platform CLI utilities."""
+
+import json
+from pathlib import Path
+
+HOME_DIRECTORY = Path.home()
+OPENBB_PLATFORM_DIRECTORY = Path(HOME_DIRECTORY, ".openbb_platform")
+SYSTEM_SETTINGS_PATH = Path(OPENBB_PLATFORM_DIRECTORY, "system_settings.json")
+
+
+def change_logging_sub_app() -> str:
+ """Build OpenBB Platform setting files."""
+ with open(SYSTEM_SETTINGS_PATH) as file:
+ system_settings = json.load(file)
+
+ initial_logging_sub_app = system_settings.get("logging_sub_app", "")
+
+ system_settings["logging_sub_app"] = "cli"
+
+ with open(SYSTEM_SETTINGS_PATH, "w") as file:
+ json.dump(system_settings, file, indent=4)
+
+ return initial_logging_sub_app
+
+
+def reset_logging_sub_app(initial_logging_sub_app: str):
+ """Reset OpenBB Platform setting files."""
+ with open(SYSTEM_SETTINGS_PATH) as file:
+ system_settings = json.load(file)
+
+ system_settings["logging_sub_app"] = initial_logging_sub_app
+
+ with open(SYSTEM_SETTINGS_PATH, "w") as file:
+ json.dump(system_settings, file, indent=4)
diff --git a/openbb_platform/core/openbb_core/app/model/system_settings.py b/openbb_platform/core/openbb_core/app/model/system_settings.py
index c5439fb760d..470e265a9b4 100644
--- a/openbb_platform/core/openbb_core/app/model/system_settings.py
+++ b/openbb_platform/core/openbb_core/app/model/system_settings.py
@@ -42,7 +42,7 @@ class SystemSettings(Tagged):
logging_handlers: List[str] = Field(default_factory=lambda: ["file"])
logging_rolling_clock: bool = False
logging_verbosity: int = 20
- logging_sub_app: Literal["python", "api", "pro"] = "python"
+ logging_sub_app: Literal["python", "api", "pro", "cli"] = "python"
logging_suppress: bool = False
log_collect: bool = True