-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[Bug] OpenBB Platform hijacks default logger #6680
Comments
Hi there, I don't believe this is a bug. Warnings and errors are handled internally by the application and passed forward. The OpenBB environment can be configured to display console messages and/or tracebacks. You can enable warnings verbosity in the file, {
"preferences": {
"show_warnings": false,
}
} Debug mode is enabled with an environment variable. This passes through the complete Exception with traceback. OPENBB_DEBUG_MODE=true @montezdesousa, do you have anything to add that can clarify? |
Thanks @deeleeramone I am still a little concerned though, because just importing a package should not alter the behavior of my app which is what’s happening. |
Hey @ncimino 👋 Thanks for bringing this to our attention. While we look into this ourselves if you have any suggestions on how to change the |
It is not standard practice for a library to alter the root logging configuration upon import, especially in a way that affects the host application's logging behavior. Libraries are expected to be good citizens in the logging ecosystem by:
In this specific case, the issue arises because OpenBB's LoggingService calls logging.basicConfig() with force=True and handlers=[] upon import, which resets the root logger configuration. This overrides any logging settings that the host application has already configured, leading to the unexpected behavior reported here. A potential fix might be: def _setup_handlers(self) -> HandlersManager:
"""Set up Logging Handlers.
Returns
-------
HandlersManager
Handlers Manager object.
"""
# Get the library-specific logger
logger = logging.getLogger('openbb')
# Configure the library's logger without affecting the root logger
logger.setLevel(self._logging_settings.verbosity)
handler = logging.StreamHandler()
formatter = logging.Formatter(
fmt=FormatterWithExceptions.LOGFORMAT,
datefmt=FormatterWithExceptions.DATEFORMAT
)
handler.setFormatter(formatter)
logger.addHandler(handler)
handlers_manager = HandlersManager(settings=self._logging_settings)
logger.info("Logging configuration finished")
logger.info("Logging set to %s", self._logging_settings.handler_list)
logger.info("Verbosity set to %s", self._logging_settings.verbosity)
logger.info(
"LOGFORMAT: %s%s",
FormatterWithExceptions.LOGPREFIXFORMAT.replace("|", "-"),
FormatterWithExceptions.LOGFORMAT.replace("|", "-"),
)
return handlers_manager This fix addresses the problem by modifying its logging setup to avoid altering the root logger configuration upon import. This change will:
Some other improvements not included here:
|
Describe the bug
By importing openbb the default logger is manipulated impacting host applications.
To Reproduce
Run this code:
Notice: That the host application messages which are printed after importing openbb no longer function the same.
At the very least it would be nice to be able to disable this behavior with a user/system setting so that the host application can control logging. Yes the application can override, but because this happens when openbb is imported it can happen at any time while the application is running. This design effectively forces the user to import openbb at a controlled location to then override these settings which is of course not ideal.
Desktop (please complete the following information):
Additional context
I believe this is due to the
LoggingService
changing the default logging configuration:https://github.com/OpenBB-finance/OpenBB/blob/develop/openbb_platform/core/openbb_core/app/logs/logging_service.py#L122-L128
The text was updated successfully, but these errors were encountered: