(self)
| 366 | return bool(self.reload or self.workers > 1) |
| 367 | |
| 368 | def configure_logging(self) -> None: |
| 369 | logging.addLevelName(TRACE_LOG_LEVEL, "TRACE") |
| 370 | |
| 371 | if self.log_config is not None: |
| 372 | if isinstance(self.log_config, os.PathLike): |
| 373 | self.log_config = os.fspath(self.log_config) |
| 374 | |
| 375 | if isinstance(self.log_config, dict): |
| 376 | if self.use_colors in (True, False): |
| 377 | self.log_config["formatters"]["default"]["use_colors"] = self.use_colors |
| 378 | self.log_config["formatters"]["access"]["use_colors"] = self.use_colors |
| 379 | logging.config.dictConfig(self.log_config) |
| 380 | elif isinstance(self.log_config, str) and self.log_config.endswith(".json"): |
| 381 | with open(self.log_config) as file: |
| 382 | loaded_config = json.load(file) |
| 383 | logging.config.dictConfig(loaded_config) |
| 384 | elif isinstance(self.log_config, str) and self.log_config.endswith((".yaml", ".yml")): |
| 385 | try: |
| 386 | import yaml |
| 387 | except ImportError as e: |
| 388 | raise ImportError( |
| 389 | "Install the PyYAML package or uvicorn[standard] to use `--log-config` with YAML files." |
| 390 | ) from e |
| 391 | |
| 392 | with open(self.log_config) as file: |
| 393 | loaded_config = yaml.safe_load(file) |
| 394 | logging.config.dictConfig(loaded_config) |
| 395 | else: |
| 396 | # See the note about fileConfig() here: |
| 397 | # https://docs.python.org/3/library/logging.config.html#configuration-file-format |
| 398 | logging.config.fileConfig(self.log_config, disable_existing_loggers=False) |
| 399 | |
| 400 | if self.log_level is not None: |
| 401 | if isinstance(self.log_level, str): |
| 402 | log_level = LOG_LEVELS[self.log_level.lower()] |
| 403 | else: |
| 404 | log_level = self.log_level |
| 405 | logging.getLogger("uvicorn.error").setLevel(log_level) |
| 406 | logging.getLogger("uvicorn.access").setLevel(log_level) |
| 407 | logging.getLogger("uvicorn.asgi").setLevel(log_level) |
| 408 | if self.access_log is False: |
| 409 | logging.getLogger("uvicorn.access").handlers = [] |
| 410 | logging.getLogger("uvicorn.access").propagate = False |
| 411 | |
| 412 | def load_app(self) -> Any: |
| 413 | """Import the app and return it. Exits on failure.""" |
no test coverage detected