apilaskowski commented on code in PR #30485:
URL: https://github.com/apache/airflow/pull/30485#discussion_r1165867929


##########
airflow/cli/commands/celery_command.py:
##########
@@ -96,6 +100,27 @@ def _serve_logs(skip_serve_logs: bool = False):
         sub_proc.terminate()
 
 
+@after_setup_logger.connect()
+def logger_setup_handler(logger, **kwargs):
+    # Setup levels at which logs go to stderr and stdout if required
+    if conf.get("logging", "celery_logging_split", fallback=None):
+        celery_formatter = logging.Formatter(DEFAULT_TASK_LOG_FMT)
+
+        class NoErrorOrAboveFilter(logging.Filter):
+            def filter(self, record):
+                return record.levelno <= logging.WARNING
+
+        below_error_handler = logging.StreamHandler(sys.stdout)
+        below_error_handler.addFilter(NoErrorOrAboveFilter())
+        below_error_handler.setFormatter(celery_formatter)
+
+        from_error_handler = logging.StreamHandler(sys.stderr)
+        from_error_handler.setLevel(logging.ERROR)
+        from_error_handler.setFormatter(celery_formatter)
+
+        logger.handlers[:] = [below_error_handler, from_error_handler]

Review Comment:
   I was also thinking about it.
   I don't think following solution is very clean, but if we want we could do:
   
   - go through all previous handlers
   - remove any StreamHandler, because we do not want duplicate logs
   - leave any FileHandlers, if they are present then user probably introduced 
them purposefully 
   
   Alternatively, if you think it is better I would suggest to put more weight 
on the fact that those handlers are cleared in documentation and docstring, so 
user selecting this flag will expect that only those two handlers will be 
present.



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to