From 1ca85623bd69f0818b72301081961fd87a3f6564 Mon Sep 17 00:00:00 2001 From: Justin Mahlik <38999128+jmahlik@users.noreply.github.com> Date: Wed, 14 Feb 2024 12:18:03 -0600 Subject: [PATCH] Fix add environment variable to disable mlflow configuring logging on import Setting MLFLOW_LOGGING_CONFIGURE_LOGGING to false disables mlflow from configuring logging on import, which may not be desired. Closes #11132 Signed-off-by: Justin Mahlik <38999128+jmahlik@users.noreply.github.com> --- mlflow/__init__.py | 6 +++++- mlflow/environment_variables.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/mlflow/__init__.py b/mlflow/__init__.py index 049a627988c6f..6ca766f719287 100644 --- a/mlflow/__init__.py +++ b/mlflow/__init__.py @@ -32,6 +32,9 @@ from mlflow.version import VERSION __version__ = VERSION +from mlflow.environment_variables import MLFLOW_CONFIGURE_LOGGING +from mlflow.utils.lazy_load import LazyLoader +from mlflow.utils.logging_utils import _configure_mlflow_loggers from mlflow import ( artifacts, # noqa: F401 @@ -82,7 +85,8 @@ transformers = LazyLoader("mlflow.transformers", globals(), "mlflow.transformers") xgboost = LazyLoader("mlflow.xgboost", globals(), "mlflow.xgboost") -_configure_mlflow_loggers(root_module_name=__name__) +if MLFLOW_CONFIGURE_LOGGING.get() is True: + _configure_mlflow_loggers(root_module_name=__name__) from mlflow.client import MlflowClient from mlflow.exceptions import MlflowException diff --git a/mlflow/environment_variables.py b/mlflow/environment_variables.py index 4a52ddd1812e0..0ed962f4454cf 100644 --- a/mlflow/environment_variables.py +++ b/mlflow/environment_variables.py @@ -511,3 +511,9 @@ def get(self): MLFLOW_GATEWAY_RATE_LIMITS_STORAGE_URI = _EnvironmentVariable( "MLFLOW_GATEWAY_RATE_LIMITS_STORAGE_URI", str, None ) + +#: Specifies whether or not to have mlflow configure logging on import. +#: If set to True, mlflow will configure ``mlflow.`` loggers with +#: logging handlers and formatters. +#: (default: ``True``) +MLFLOW_CONFIGURE_LOGGING = _BooleanEnvironmentVariable("MLFLOW_LOGGING_CONFIGURE_LOGGING", True)