Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] Make "logging_suppress" in SystemSettings Mutable and Then Actually Suppress Logging Service #6933

Merged
merged 8 commits into from
Nov 11, 2024
9 changes: 6 additions & 3 deletions openbb_platform/core/openbb_core/app/logs/handlers_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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
80 changes: 41 additions & 39 deletions openbb_platform/core/openbb_core/app/logs/logging_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
deeleeramone marked this conversation as resolved.
Show resolved Hide resolved
# 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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class SystemService(metaclass=SingletonMeta):
"api_settings",
"python_settings",
"debug_mode",
"logging_suppress",
}

PRO_VALIDATION_HASH = "300ac59fdcc8f899e0bc5c18cda8652220735da1a00e2af365efe9d8e5fe8306" # pragma: allowlist secret
Expand Down
Loading