ashb commented on code in PR #69916:
URL: https://github.com/apache/airflow/pull/69916#discussion_r3596670132


##########
shared/logging/tests/logging/test_structlog.py:
##########
@@ -451,6 +451,62 @@ def test_logger_filtering(structlog_config, levels):
         """)
 
 
+def test_namespace_levels_filter_stdlib_loggers(structlog_config):
+    logger = logging.getLogger("stdlib_namespace")
+    child_logger = logging.getLogger("stdlib_namespace.child")
+    previous_levels = {logger: logger.level, child_logger: child_logger.level}
+
+    try:
+        with structlog_config(
+            colors=False,
+            log_format="[%(name)s] %(message)s",
+            log_level="DEBUG",
+            namespace_log_levels="stdlib_namespace=WARNING",
+        ) as sio:
+            logger.info("Filtered parent message")
+            child_logger.info("Filtered child message")
+            logging.getLogger("other_stdlib_namespace").info("Visible message")
+            child_logger.warning("Visible warning")
+    finally:
+        for configured_logger, level in previous_levels.items():
+            configured_logger.setLevel(level)
+
+    assert sio.getvalue() == textwrap.dedent("""\
+        [other_stdlib_namespace] Visible message
+        [stdlib_namespace.child] Visible warning
+        """)
+
+
+def 
test_namespace_levels_allow_stdlib_logger_below_global_level(structlog_config):
+    parent_logger = logging.getLogger("stdlib_parent")
+    child_logger = logging.getLogger("stdlib_parent.child")
+    previous_levels = {parent_logger: parent_logger.level, child_logger: 
child_logger.level}
+
+    try:
+        with structlog_config(
+            colors=False,
+            log_format="[%(name)s] %(message)s",
+            log_level="INFO",
+            namespace_log_levels="stdlib_parent=WARNING 
stdlib_parent.child=DEBUG",
+        ) as sio:
+            parent_logger.info("Filtered parent message")
+            child_logger.debug("Visible child message")
+            logging.getLogger("other_stdlib_logger").debug("Filtered other 
message")
+    finally:
+        for configured_logger, level in previous_levels.items():
+            configured_logger.setLevel(level)
+
+    assert sio.getvalue() == "[stdlib_parent.child] Visible child message\n"
+
+
[email protected]("logging.config.dictConfig", autospec=True)
+def test_alembic_runtime_plugin_logger_defaults_to_warning(mock_dict_config):
+    configure_logging(log_level="INFO")
+
+    logging_config = mock_dict_config.call_args.args[0]
+    assert logging_config["loggers"]["alembic.runtime.plugins"] == {"level": 
"WARN"}

Review Comment:
   This is testing the wrong thing I think. We don't care what it is called 
with, we care what the specific logger is configured with



-- 
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]

Reply via email to