code: def test_logging_extended():
      """
      Test extended ("new-style") logging configuration.
      """
      c = {
          "logging": {
              "version": "1",
              "formatters": {
                  "simple": {
                      "format": "%(levelname)s: %(name)s: %(message)s"
                  }
              },
              "handlers": {
                  "console": {
                      "class": "logging.StreamHandler",
                      "stream": "ext://sys.stderr",
                      "formatter": "simple",
                  }
              },
              "loggers": {
                  "distributed.foo": {
                      "level": "INFO",
                      # 'handlers': ['console'],
                  },
                  "distributed.foo.bar": {
                      "level": "ERROR",
                      # 'handlers': ['console'],
                  },
              },
              "root": {"level": "WARNING", "handlers": ["console"]},
          }
      }
      # Must test using a subprocess to avoid wrecking pre-existing configuration
      with new_config_file(c):
          code = """if 1:
              import logging
  
              from distributed.utils_test import captured_handler
  
              root = logging.getLogger()
              d = logging.getLogger('distributed')
              df = logging.getLogger('distributed.foo')
              dfb = logging.getLogger('distributed.foo.bar')
  
              with captured_handler(root.handlers[0]) as root_log:
                  df.info("1: info")
                  dfb.warning("2: warning")
                  dfb.error("3: error")
                  d.info("4: info")
                  d.warning("5: warning")
  
              root_log = root_log.getvalue().splitlines()
              print(root_log)
  
              assert root_log == [
                  "INFO: distributed.foo: 1: info",
                  "ERROR: distributed.foo.bar: 3: error",
                  "WARNING: distributed: 5: warning",
                  ]
              """
  
          subprocess.check_call([sys.executable, "-c", code])
  
imports: from __future__ import annotations
  import contextlib
  import logging
  import os
  import re
  import subprocess
  import sys
  import tempfile
  import textwrap
  import pytest
  import yaml
  import dask.config
  from distributed.config import initialize_logging
  from distributed.utils_test import captured_handler, new_config, new_config_file
label_desc: Use image node_id 4 for calling a global function with example usage: test_logging_extended() without return types