uranusjr commented on code in PR #32781:
URL: https://github.com/apache/airflow/pull/32781#discussion_r1271612179
##########
airflow/utils/serve_logs.py:
##########
@@ -44,7 +44,31 @@ def create_app():
flask_app = Flask(__name__, static_folder=None)
expiration_time_in_seconds = conf.getint("webserver",
"log_request_clock_grace", fallback=30)
log_directory = os.path.expanduser(conf.get("logging", "BASE_LOG_FOLDER"))
-
+ log_config_class = conf.get("logging", "logging_config_class")
+ if log_config_class is not None:
+ logger.info(f"Detected user-defined logging config. Attempting to load
{log_config_class}")
+ try:
+ import importlib
+
+ module_name, dict_name = log_config_class.split(".")
+ module = importlib.import_module(module_name)
+ logging_config = getattr(module, dict_name)
+ handler_config = logging_config.get("handlers", {})
+ task_config = handler_config.get("task", {})
+ base_log_folder = task_config.get("base_log_folder", None)
+ if base_log_folder is not None:
+ log_directory = base_log_folder
+ logger.info(
+ f"Successfully imported user-defined logging config. "
+ f"Flask App will serve log from {log_directory}"
+ )
+ else:
+ logger.warning(
+ f"User-defined logging config does not specify
'base_log_folder'. "
+ f"Flask App will use default log directory {log_directory}"
+ )
Review Comment:
```suggestion
try:
base_log_folder = logging_config["handlers"]["task"]
except KeyError:
base_log_folder = None
if base_log_folder is not None:
log_directory = base_log_folder
logger.info(
"Successfully imported user-defined logging config. "
"Flask App will serve log from %s",
log_directory,
)
else:
logger.warning(
"User-defined logging config does not specify
'base_log_folder'. "
"Flask App will use default log directory %s",
base_log_folder,
)
```
##########
airflow/utils/serve_logs.py:
##########
@@ -44,7 +44,31 @@ def create_app():
flask_app = Flask(__name__, static_folder=None)
expiration_time_in_seconds = conf.getint("webserver",
"log_request_clock_grace", fallback=30)
log_directory = os.path.expanduser(conf.get("logging", "BASE_LOG_FOLDER"))
-
+ log_config_class = conf.get("logging", "logging_config_class")
+ if log_config_class is not None:
+ logger.info(f"Detected user-defined logging config. Attempting to load
{log_config_class}")
Review Comment:
```suggestion
logger.info("Detected user-defined logging config. Attempting to
load %s", log_config_class)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]