Repository: OpenBB-finance/OpenBB
Pull request: [BugFix] Make "logging_suppress" in `SystemSettings` Mutable and Then Actually Suppress Logging Service
1. **Why**?:

    - To provide users with a way to resolve #6926 locally.
      - This PR provides a kill switch to completely disable the LoggingService.
    - The `SystemSettings` class has an attribute, `logging_suppress`, and it is immutably set as `False`.
    - Even if it was mutable, there is no reference to this setting anywhere in the code, it won't do anything.


2. **What**? :

    - Allows `logging_suppress` to be defined in `system_settings.json`.
    - When `true`, the `file` and `PostHog` handlers are not added, nothing gets recorded to the `~/OpenBBUserData/logs` folder.

3. **Impact**:

    - Improves compatibility over VPN and blocking network infrastructure.
    - Improves user privacy by offering a complete offramp to the logging service.

4. **Testing Done**:

    -  Add to`system_settings.json` and observe that no startup log file is created.:
 
```json
{
    "logging_suppress": true
}
```  



Problem statement:
[Bug] Getting a HTTPS error pointing to us.i.posthog.com when running the basic getting started code
**Describe the bug**
When following the getting started guide, I ran the basic code to get historical data of AAPL, I got this error message: `error uploading: HTTPSConnectionPool(host='us.i.posthog.com', port=443): Max retries exceeded with url: /batch/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7b6d04bacb50>: Failed to establish a new connection: [Errno 111] Connection refused'))`

However, i still managed to get the data of the AAPL ticker. It is just annoying to constantly see that error and it is taking a long time to run - not sure what is causing this.

I am seeing:
{above error}
{results}
{above error"

So the error message poped up twice.

**To Reproduce**
1. Create python env and activate it
2. Run `pip install 'openbb[all]'`
3. Add the following lines to a python file:
`from openbb import obb`
`output = obb.equity.price.historical("AAPL")`
`df = output.to_dataframe()`
`df.head()`

4. Run the python file
Output:

`error uploading: HTTPSConnectionPool(host='us.i.posthog.com', port=443): Max retries exceeded with url: /batch/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f5787b3c490>: Failed to establish a new connection: [Errno 111] Connection refused'))`

`            open  high   low  close      volume
date                                           
2004-01-02  0.39  0.39  0.38   0.38  2024993600
2004-01-05  0.38  0.40  0.38   0.40  5530257600
2004-01-06  0.40  0.40  0.39   0.40  7130872000
2004-01-07  0.40  0.41  0.39   0.41  8216241600
2004-01-08  0.41  0.42  0.41   0.42  6444244800`

`error uploading: HTTPSConnectionPool(host='us.i.posthog.com', port=443): Max retries exceeded with url: /batch/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f5787b604d0>: Failed to establish a new connection: [Errno 111] Connection refused'))`

**Desktop (please complete the following information):**

- OS: Pop!_OS 22.04 LTS
- Python version: 3.11.5

Hints from issue discussion:
Hi there,

What kind of machine is this, a virtual machine or a desktop? Are you connected to the internet via VPN or other kind of proxy?

Can you try, @seantanjx, adding the items below to a file called "system_settings.json"?  This is located in a folder called ".openbb_platform", at the root of the OS user account. If the file does not exist, create a new one.

```json
{
    "log_collect": false
}
```

Commit message: no startup log if true

Patch to review:
diff --git a/openbb_platform/core/openbb_core/app/logs/handlers_manager.py b/openbb_platform/core/openbb_core/app/logs/handlers_manager.py
index 8e79d932f0ec..deeaff8d5e5e 100644
--- a/openbb_platform/core/openbb_core/app/logs/handlers_manager.py
+++ b/openbb_platform/core/openbb_core/app/logs/handlers_manager.py
@@ -35,9 +35,9 @@ def setup(self):
                 self._add_stderr_handler()
             elif handler_type == "noop":
                 self._add_noop_handler()
-            elif handler_type == "file":
+            elif handler_type == "file" and not self._settings.logging_suppress:
                 self._add_file_handler()
-            elif handler_type == "posthog":
+            elif handler_type == "posthog" and not self._settings.logging_suppress:
                 self._add_posthog_handler()
             else:
                 self._logger.debug("Unknown log handler.")
@@ -81,6 +81,9 @@ def update_handlers(self, settings: LoggingSettings):
         """Update the handlers with new settings."""
         logger = self._logger
         for hdlr in logger.handlers:
-            if isinstance(hdlr, (PathTrackingFileHandler, PosthogHandler)):
+            if (
+                isinstance(hdlr, (PathTrackingFileHandler, PosthogHandler))
+                and not settings.logging_suppress
+            ):
                 hdlr.settings = settings
                 hdlr.formatter.settings = settings  # type: ignore
diff --git a/openbb_platform/core/openbb_core/app/logs/logging_service.py b/openbb_platform/core/openbb_core/app/logs/logging_service.py
index 9c1900b0c022..a81c6d8de988 100644
--- a/openbb_platform/core/openbb_core/app/logs/logging_service.py
+++ b/openbb_platform/core/openbb_core/app/logs/logging_service.py
@@ -217,42 +217,44 @@ def log(
         )
         self._handlers_manager.update_handlers(self._logging_settings)
 
-        if "login" in route:
-            self._log_startup(route, custom_headers)
-        else:
-
-            # Remove CommandContext if any
-            kwargs.pop("cc", None)
-
-            # Get provider for posthog logs
-            passed_model = kwargs.get("provider_choices", DummyProvider())
-            provider = (
-                passed_model.provider
-                if hasattr(passed_model, "provider")
-                else "not_passed_to_kwargs"
-            )
-
-            # Truncate kwargs if too long
-            kwargs = {k: str(v)[:100] for k, v in kwargs.items()}
-            # Get execution info
-            error = None if all(i is None for i in exec_info) else str(exec_info[1])
-
-            # Construct message
-            message_label = "ERROR" if error else "CMD"
-            log_message = json.dumps(
-                {
-                    "route": route,
-                    "input": kwargs,
-                    "error": error,
-                    "provider": provider,
-                    "custom_headers": custom_headers,
-                },
-                default=to_jsonable_python,
-            )
-            log_message = f"{message_label}: {log_message}"
-            log_level = self._logger.error if error else self._logger.info
-            log_level(
-                log_message,
-                extra={"func_name_override": func.__name__},
-                exc_info=exec_info,
-            )
+        if not self._logging_settings.logging_suppress:
+
+            if "login" in route:
+                self._log_startup(route, custom_headers)
+            else:
+
+                # Remove CommandContext if any
+                kwargs.pop("cc", None)
+
+                # Get provider for posthog logs
+                passed_model = kwargs.get("provider_choices", DummyProvider())
+                provider = (
+                    passed_model.provider
+                    if hasattr(passed_model, "provider")
+                    else "not_passed_to_kwargs"
+                )
+
+                # Truncate kwargs if too long
+                kwargs = {k: str(v)[:100] for k, v in kwargs.items()}
+                # Get execution info
+                error = None if all(i is None for i in exec_info) else str(exec_info[1])
+
+                # Construct message
+                message_label = "ERROR" if error else "CMD"
+                log_message = json.dumps(
+                    {
+                        "route": route,
+                        "input": kwargs,
+                        "error": error,
+                        "provider": provider,
+                        "custom_headers": custom_headers,
+                    },
+                    default=to_jsonable_python,
+                )
+                log_message = f"{message_label}: {log_message}"
+                log_level = self._logger.error if error else self._logger.info
+                log_level(
+                    log_message,
+                    extra={"func_name_override": func.__name__},
+                    exc_info=exec_info,
+                )
diff --git a/openbb_platform/core/openbb_core/app/logs/models/logging_settings.py b/openbb_platform/core/openbb_core/app/logs/models/logging_settings.py
index f44ed423c6b7..ec8e412db336 100644
--- a/openbb_platform/core/openbb_core/app/logs/models/logging_settings.py
+++ b/openbb_platform/core/openbb_core/app/logs/models/logging_settings.py
@@ -49,6 +49,8 @@ def __init__(
         self.platform: str = system_settings.platform
         self.python_version: str = system_settings.python_version
         self.platform_version: str = system_settings.version
+        self.logging_suppress: bool = system_settings.logging_suppress
+        self.log_collect: bool = system_settings.log_collect
         # User
         self.user_id: Optional[str] = user_id
         self.user_logs_directory: Path = get_log_dir(user_data_directory)
diff --git a/openbb_platform/core/openbb_core/app/service/system_service.py b/openbb_platform/core/openbb_core/app/service/system_service.py
index 4d9f9c6feeb3..c9e3165e1790 100644
--- a/openbb_platform/core/openbb_core/app/service/system_service.py
+++ b/openbb_platform/core/openbb_core/app/service/system_service.py
@@ -22,6 +22,7 @@ class SystemService(metaclass=SingletonMeta):
         "api_settings",
         "python_settings",
         "debug_mode",
+        "logging_suppress",
     }
 
     PRO_VALIDATION_HASH = "300ac59fdcc8f899e0bc5c18cda8652220735da1a00e2af365efe9d8e5fe8306"  # pragma: allowlist secret


Code review comments:
diff_hunk: @@ -217,42 +217,44 @@ def log(
         )
         self._handlers_manager.update_handlers(self._logging_settings)
 
-        if "login" in route:
-            self._log_startup(route, custom_headers)
-        else:
-
-            # Remove CommandContext if any
-            kwargs.pop("cc", None)
-
-            # Get provider for posthog logs
-            passed_model = kwargs.get("provider_choices", DummyProvider())
-            provider = (
-                passed_model.provider
-                if hasattr(passed_model, "provider")
-                else "not_passed_to_kwargs"
-            )
-
-            # Truncate kwargs if too long
-            kwargs = {k: str(v)[:100] for k, v in kwargs.items()}
-            # Get execution info
-            error = None if all(i is None for i in exec_info) else str(exec_info[1])
-
-            # Construct message
-            message_label = "ERROR" if error else "CMD"
-            log_message = json.dumps(
-                {
-                    "route": route,
-                    "input": kwargs,
-                    "error": error,
-                    "provider": provider,
-                    "custom_headers": custom_headers,
-                },
-                default=to_jsonable_python,
-            )
-            log_message = f"{message_label}: {log_message}"
-            log_level = self._logger.error if error else self._logger.info
-            log_level(
-                log_message,
-                extra={"func_name_override": func.__name__},
-                exc_info=exec_info,
-            )
+        if not self._logging_settings.logging_suppress:
+
+            if "login" in route:
+                self._log_startup(route, custom_headers)
+            else:
+
+                # Remove CommandContext if any
+                kwargs.pop("cc", None)
+
+                # Get provider for posthog logs
+                passed_model = kwargs.get("provider_choices", DummyProvider())
+                provider = (
+                    passed_model.provider
+                    if hasattr(passed_model, "provider")
+                    else "not_passed_to_kwargs"
+                )
+
+                # Truncate kwargs if too long
+                kwargs = {k: str(v)[:100] for k, v in kwargs.items()}
path: openbb_platform/core/openbb_core/app/logs/logging_service.py
text: @user1:
since we are in here -- can we do future me a solid and make this a larger clip.  maybe like :300

@author:
300 it is.